【发布时间】:2019-03-01 13:10:31
【问题描述】:
我尝试了以下代码来提取域,并且在定义变量时效果很好
$ADS = 'CN=Lamda,OU=OU_Bloquage,DC=Adminstrateur,DC=6NLG-AD'
但是当我把$ADS改成
$ADS = Get-ADUser -Identity 'Lamda' -Properties DistinguishedName |
select DistinguishedName`
我想要的结果是:
DC=管理员,DC=6NLG-AD`下面是我写的代码
$ADS = Get-ADUser -Identity 'Lamda' -Properties DistinguishedName |
select DistinguishedName
$pattern = '(?i)DC=\w{1,}?\b'
([RegEx]::Matches($ADS, $pattern) | ForEach-Object { $_.Value }) -join ','
【问题讨论】:
-
select DistinguishedName->select -Expand DistinguishedName -
正如 AnsgarWiechers 指出的那样,您的问题是您的数据位于对象的属性中,而不是它自己的对象中。 [grin] 您可以使用
Select-Object扩展该属性,或者在您的代码中寻址该属性。使用$ADS.DistinguishedName而不是$ADS -
我修改了
select DistinguishedName -> select -Expand DistinguishedName并对其进行了测试,但出现以下错误:Move-ADObject:Operation could not be affected because object parent was not created or was deleted -
你没有向我们展示你做
Move-ADObject的部分。问题只是如何拆分专有名称..
标签: powershell ou distinguishedname