Powershell 如果格式化

标签 powershell if-statement foreach

我正在尝试运行下面的脚本,但是当我运行时我得到了

Unexpected token '-PrimaryUserAddress' in expression or statement

我该如何解决这个问题?

$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"
 }
}

最佳答案

解析器正在命中 - 并将其解释为 Powershell 运算符。单引号属性,以便将其解释为文字字符串:

if($user.'msRTCSIP-PrimaryUserAddress' -ne 0)

关于Powershell 如果格式化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21938552/

相关文章:

PowerShell -gt 比较运算符不起作用

powershell - 如何在 PowerShell 中循环访问数据集?

javascript - 一起显示英里每小时和公里每小时?

r - 使用 if 语句对数字进行分类的循环

javascript - 使用 javascript 设置每个项目的属性

powershell - 从ConvertFrom-StringData飞溅单行字符串时出错

.net - 如何使用 powershell 脚本在 IIS 中启动和停止应用程序池

c# - 如何以不同的顺序执行两个代码片段?

Javascript - 如何在循环中查找不匹配?

PowerShell:如果未找到字符串,则会出现不必要的错误