0
我想的CSV文件導出爲「ParentGroupName」欄目,「成員名稱」,「顯示名稱」PowerShell的導出CSV的列
目前,它是出口三個DATAS一列。
function getGroups{
$Groups += Get-ADGroup -Filter * -SearchBase "ou=Groups,ou=DCM,ou=NTG,dc=prod,dc=main,dc=ntgov" | Select-Object -ExpandProperty samaccountname
return $Groups
}
Measure-Command{
$Groups = getGroups
write-host "Groups:" $Groups.Count
}
Measure-Command{
$date = $(get-date).ToString("dd MMM yyyy")
$global:FileName = "Active Directory Group Membership - DCM -" + $date
$stringBuilder = New-Object System.Text.StringBuilder
foreach ($GroupName in $Groups){
Get-ADGroupMember -Identity $GroupName | Sort-Object $_.SamAccountName | ForEach-Object {
$ParentGroupName = (Get-ADGroup -Identity $GroupName).SamAccountName
$MemberName = $_.SamAccountName # Member of the Group.
if ($_.ObjectClass -eq 'group') {
$DisplayName = ' - '
} elseif ($_.ObjectClass -eq 'user') {
$a = (Get-ADUser -Identity $MemberName -Properties Displayname)
$DisplayName = $a.DisplayName
}
$null = $stringBuilder.Append("$ParentGroupName, $MemberName, $DisplayName")
}
}
outputArray = $stringBuilder.ToString()
out-file C:\Users\augut\Desktop\$FileName.csv
outputArray | out-file C:\Users\augut\Desktop\$FileName.csv
}
感謝它主要作品接受這似乎爲每個組名和用戶名重複一個名字的顯示名: 例如: mjms \t傑恩Fairnington \t DCM_NTH_FOI TP6 \t傑恩Fairnington \t DCM_NTH_FOI yfair \t傑恩Fairnington \t DCM_NTH_FOI ktimi \t傑恩Fairnington \t zzMinisterVowles_O BXL職員 的職員 amart \t傑恩Fairnington \t DCM OCM科長\t傑恩Fairnington \t DCM_DNH_SPIO_RW FMD \t傑恩Fairnington \t DCM_DNH_SPIO_RW MAT \t傑恩Fairnington \t DCM_DNH_SPIO_RW aleon \t傑恩Fairnington \t DCM OCM首席bqb \t Jayne Fairnington \t DCM OCM Chief of Staffs – GuzziT
@GuzziT我剛剛做了一個小編輯,嘗試新版本。 – alroc
嘗試更新的版本,但沒有變化 – GuzziT