简体   繁体   English

PS从AD获取信息:group_name,employeeid,name,samacoountname

[英]PS to get info from AD: group_name, employeeid, name, samacoountname

I am trying to get some info from AD. 我正在尝试从广告中获取一些信息。 I need a csv with 4 columns: group_name, emplyeeid, name and sammacount name for several security groups. 我需要一个包含4列的csv:几个安全组的group_name,emplyeeid,name和sammacount名称。 I have the first one that gets me the group member and the name: Get-ADGroup -Filter {Name -like "security_group*"} | 我有第一个获取组成员和名称的人:Get-ADGroup -Filter {Name -like“ security_group *”} | foreach {$group = foreach {$ group =

$_.Name;  Get-ADGroupMember $group | select @{N='group'; E={$group}},Name} | select group,Name| Export-CSV -Path C:\temp\test.csv 

And another one that gets me the employeeid, name, samacoountname: 还有一个让我获得employeeid,名字,samacoountname的名字:

Get-ADGroup -filter {Name -like "group_name*"} |
foreach { 
 Write-Host "Exporting $($_.name)"
 $name = $_.name -replace " ","-"
 $file = Join-Path -path "C:\temp\test" -ChildPath "$name.csv"
 Get-ADGroupMember -Identity $_.distinguishedname -Recursive |  
 Get-ADObject -Properties SamAccountname,employeeid |
 Select employeeid,Name,SamAccountName |
 Export-Csv -Path $file -NoTypeInformation
}

This gets me a different csv file for every group. 这给我每个组一个不同的csv文件。 That's ok, because I can copy all to the same csv. 可以,因为我可以将所有内容复制到同一csv中。 I have tried to put all this into one script to give me all 4 colums, but I can't seem to get it right. 我试图将所有这些放到一个脚本中,以便给我所有4个列,但是我似乎无法正确地做到这一点。 Any help would be appreciated! 任何帮助,将不胜感激!

I figured it out: 我想到了:

Get-ADGroup -filter {Name -like "group_name*"} |
foreach { 
 Write-Host "Exporting $($_.name)"
 $name = $_.name -replace " ","-"
 $file = Join-Path -path "C:\temp\test" -ChildPath "$name.csv"
 Get-ADGroupMember -Identity $_.distinguishedname -Recursive |  
 Get-ADObject -Properties SamAccountname,employeeid |
 Select @{N='group'; E={$name}},employeeid,Name,SamAccountName |
 Export-Csv -Path $file -NoTypeInformation
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM