2017-10-17 83 views
-4

我能够导出我的Active Directory OU账户CSV文件删除“OU =域控制器”但问题是,我得到这样的输出:在导出的CSV文件在PowerShell中

"Domain Controllers","OU=Domain Controllers,DC=testlab,DC=com" 

我只是想有一个输出就像这样:

"Domain Controllers","DC=testlab,DC=com" 

这里是我的脚本现在:

import-module activedirectory 
Get-ADOrganizationalUnit -filter * | select Name,@{l='DistinguishedName';e={($_.DistinguishedName)}} | Export-Csv -Path "C:\temp\ADOrganizationalUnitsexport.csv" -NoTypeInformation 
+0

猜你甚至没有试图研究这个自己,就像你会发现'Replace'完全符合你的要求。 –

+2

[PowerShell从字符串中删除文本]的可能重复(https://stackoverflow.com/questions/19168475/powershell-to-remove-text-from-a-string) –

回答

0

那么如果你只是想在网络第一个和第三个选项,你可以使用分割和结合​​这样的:

Get-ADOrganizationalUnit -filter * | 
Select Name,@{l='DistinguishedName';e={(($_.DistinguishedName -split ','))[0,2] -join ','}} | 
Export-Csv -Path "C:\temp\ADOrganizationalUnitsexport.csv" -NoTypeInformation 

知道,它不会在所有情况下工作,因为有时你之前和之后有更多的OU的,所以你必须找到正确的方法,这只是给你一个方向。

而且,当然你也可以使用替代和一些其他的选择,但你必须做一些研究,并投入一定精力来得到正确的结果...