我想在 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/