Test.psm1이라는 PowerShell 모듈이 있습니다. 변수에 값을 설정하고 해당 모듈에서 다른 메서드를 호출 할 때 해당 변수에 액세스 할 수있게하려고합니다.PowerShell 모듈의 속성 설정
#Test.psm1
$property = 'Default Value'
function Set-Property([string]$Value)
{
$property = $Value
}
function Get-Property
{
Write-Host $property
}
Export-ModuleMember -Function Set-Property
Export-ModuleMember -Function Get-Property
PS 명령 행에서
: 나는 "새로운 가치"를 반환 할이 시점에서
Import-Module Test
Set-Property "New Value"
Get-Property
하지만 "기본 값"을 반환합니다. 그 변수의 범위를 설정하는 방법을 찾으려고했지만 행운이 없었습니다.
+1 모듈에는 발신자의 환경에서 모듈이 우연히 오염되지 않도록 모듈을 보호하는 자체 범위가 있습니다. – JPBlanc