[英]How can I split AD information in Powershell into a excel document?
I am a Powershell starter. 我是Powershell入门者。 I have been trying to create a script, that makes an Excel file with some AD information including the
DistinguishedName
. 我一直在尝试创建一个脚本,该脚本使用一些包括
DistinguishedName
AD信息来制作一个Excel文件。 My script looks like this: 我的脚本如下所示:
$dn = Get-ADUser -Filter * -SearchBase "OU=Users,OU=Ch01,OU=EU,DC=corp,DC=ads" | select DistinguishedName,SamAccountName,name |export-csv C:\\temp\\test1.csv -Delimiter ";"
An example of what I get (Note: |
means new cell in Excel): 我得到的示例(注意:
|
表示Excel中的新单元格):
CN=Testuser\, Verfluecht,OU=Users,OU=Ch01,OU=EU,DC=corp,DC=ads | vtestuser | Testuser, Verfluecht
But in order to group the paths in excel, I need it without the CN (CN=Testuser\\, Verfluecht,) So that it would look like this: 但是为了在excel中对路径进行分组 ,我需要没有CN(CN = Testuser \\,Verfluecht,),因此它看起来像这样:
OU=Users,OU=Ch01,OU=EU,DC=corp,DC=ads | vtestuser | Testuser, Verfluecht
How can I do this? 我怎样才能做到这一点?
I tried many things such as .substring and replace, but I could not get it done. 我尝试了很多事情,例如.substring和replace,但是我做不到。
Using this link and a calculated property, it should just drop the first part of the distinguishedname and be left with the parts you need. 使用此链接和计算所得的属性,它应该只删除可分辨名称的第一部分,并保留所需的部分。
Get-ADUser -Filter * -SearchBase "OU=Users,OU=Ch01,OU=EU,DC=corp,DC=ads" |
Select-Object @{Name="DistinguishedName";Expression={$_.distinguishedname | ForEach-Object {$_ -replace '^.+?(?<!\\),',''}}},samaccountname,name |
Export-Csv C:\temp\test1.csv -Delimiter ";"
On my test environment, I get the output below (without piping it to Export-Csv). 在我的测试环境中,我得到下面的输出(不将其通过管道传递到Export-Csv)。
Get-ADUser -Filter * | Select-Object @{Name="DistinguishedName";Expression={$_.distinguishedname | ForEach-Object {$_ -replace '^.+?(?<!\\),',''}}},samaccountname,name
DistinguishedName samaccountname name
----------------- -------------- ----
CN=Users,DC=timhaintz,DC=com Administrator Administrator
CN=Users,DC=timhaintz,DC=com Guest Guest
CN=Users,DC=timhaintz,DC=com DefaultAccount DefaultAccount
CN=Users,DC=timhaintz,DC=com krbtgt krbtgt
Thanks, Tim. 谢谢,蒂姆。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.