1
我正在尝试使用用户实际名称替换部分AD专有名称列中的内容。PowerShell使用正则表达式模式选择查询作为子表达式
IE:
格局$ _ identity.DistinguishedName
CN=Touchdown§3939303030313134393535383932,CN=ExchangeActiveSyncDevices,CN=Guy\, Some,OU=Employees,OU=Departments and Categories,DC=something,DC=com
一个内衬不起作用
$devices | Select @{N="Name";E={ (Get-AdUser -Identity ($_.Identity.DistinguishedName -match ".*\,CN=ExchangeActiveSyncDevices\,(.*)" | Out-Null; $Matches[1])).Name }}
仅此一项工程....
$devices[0].Identity.DistinguishedName -match ".*\,CN=ExchangeActiveSyncDevices\,(.*)" | Out-Null; $Matches[1]
和显示器。 ..
CN=Guy\, Some,OU=Employees,OU=Departments and Categories,DC=something,DC=com
这也适用,这是类似我想要实现的,但不允许我参加的distinguishedName去查找实际名称。
$devices | Select @{N="Name";E={ $_.Identity.DistinguishedName -match ".*\,CN=ExchangeActiveSyncDevices\,(.*)" | Out-Null; $Matches[1] }}
只要你尝试这样做它打破了,因为我假设你不准使用;在Get-ADUser中提供该身份参数时打破下一个命令。
Get-ADUser -Identity ($devices[0].Identity.DistinguishedName -match ".*\,CN=ExchangeActiveSyncDevices\,(.*)" | Out-Null; $Matches[1])
一个将如何通过使用选择表达式而不必填充了一个全新的单独的变量,并与修改后的内容替换原始内容做到这一点?
哦,好,我想我现在明白了一个更好的方式来做到这一点。使用$ _。Identity.DistinguishedName -match“。* \,CN = ExchangeActiveSyncDevices \,(。*)”返回true,这是Out-Null的目的,掩盖了真实情况,然后我使用了matches变量提取实际的字符串。用你的方法,我们不会返回true-false。我只知道 - 匹配。谢谢! – arodd 2013-05-01 15:33:17