Powershell:Where-Object 通配符

标签 powershell active-directory

我想在 Active Directory 用户的所有属性中搜索特定电话号码/分机号。

我可以像这样获取所有属性:

get-aduser joesmith -Properties *

但我想过滤结果,例如分机号 1234(可能在很多地方,例如 extensionAttribute1、OfficePhone、HomePhone、Mobile 等)。

我试过:

get-aduser joesmith -Properties * | where-object {$_ -like "*1234*" }

但是where-object要的是$_.value,我不知 Prop 体值。

我应该如何搜索多个属性的值?我希望看到如下结果:

mobile        1234
officephone   12345
othermobile   61234

最佳答案

要遍历您不知道名称的属性的值(即 OfficePhone、CustomAttribute2、mobile),您可以使用以下方法:

get-aduser joesmith -Properties * | foreach-object { 
  foreach ($property in $_.PSObject.Properties) {
    if ($property.value -like "*1234*") {
      "$($property.name) $($property.value)"
    }
  }
}

关于Powershell:Where-Object 通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22794693/

相关文章:

powershell - 如何使用 Powershell 从电子邮件中获取 samaccountname?

powershell - 排队 MSI 安装 - 通过 Powershell

Powershell 编辑 mp3 信息

powershell - CSV中的单元格计算不正确。显示错误的号码。得到错误

powershell - 为什么Get-ADObject无法正确过滤ObjectClass =“user”?

python - LDAP 查询过滤具有 *x* 等组的用户

powershell - 使用 Azure Powershell 获取角色即时状态

active-directory - LDAP 错误 "User Name Not Found"

powershell - 我应该使用 Active Directory 模块 cmdlet 还是 DirectoryServices .NET 类

java - 在 Active Directory LDAP 中添加具有密码的用户