Joe*_*Rod 3 powershell foreach if-statement
我正在尝试运行以下脚本,但是当我这样做时,我得到了
表达式或语句中出现意外的标记'-PrimaryUserAddress'
我怎样才能解决这个问题?
$users = Get-ADUser "joerod" -Properties *|Select-Object SamAccountName, msRTCSIP-PrimaryUserAddress
ForEach ($user in $users) {
if($user.msRTCSIP-PrimaryUserAddress -ne 0){
Write-Host "Removing $($user.samaccountname) from OCS"
}
}
Run Code Online (Sandbox Code Playgroud)
解析器正在点击它 - 并将其解释为Powershell运算符.单引用该属性,以便将其解释为文字字符串:
if($user.'msRTCSIP-PrimaryUserAddress' -ne 0)
Run Code Online (Sandbox Code Playgroud)