Ask Your Question
4

How to assign a value to a static member using a dot-sourced file?

asked 2023-07-20 17:55:18 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-20 18:10:01 +0000

devzero gravatar image

To assign a value to a static member using a dot-sourced file, follow these steps:

  1. Create a PowerShell script with the static member you want to assign a value to.

Example:

# MyScript.ps1
class MyClass {
    static $MyStaticMember
}
  1. In your main PowerShell script, dot-source the script containing the static member.

Example:

. .\MyScript.ps1
  1. Once the script is loaded, you can assign a value to the static member using the class name and property name.

Example:

MyClass::$MyStaticMember = "Hello, world!"
  1. You can then access the value of the static member using the class name and property name.

Example:

Write-Host MyClass::$MyStaticMember

This will output "Hello, world!" to the console.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-20 17:55:18 +0000

Seen: 15 times

Last updated: Jul 20 '23