在powershell中,以下工作符合预期:
function SetProps([ref]$variable)
{
$variable.value += "Hello"
}
$val = New-Object Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
SetProps ([ref]$val)
$val
变量$val
附加“Hello”。
但是,此示例不起作用:
Import-Module ActiveDirectory
$users = Get-ADUser -Filter * -SearchBase "OU=Users,DC=sample,DC=local" -Properties EmailAddress, ProxyAddresses
function SetProps([ref]$props){
$props.Value += "Hello"
}
foreach($user in $users){
SetProps ([ref]$user.proxyAddresses)
$user.proxyAddresses
}
“Hello”不会附加到proxyAddresses。谁能告诉我为什么?