Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.