2016-07-31 7 views
2

Der folgende Code soll alle Mitglieder einer bestimmten übergeordneten Supportgruppe auflisten. Ich möchte alle Werte im "Mitglieder" -Array trennen und diese Kommata in die Ausgabe in CSV einbeziehen. Wie kann ich das tun?Ausgabe in CSV enthält Kommata

Set-ExecutionPolicy Bypass -Force 

#Report start of script actions. 
Write-Output "Discovering Security Group members..." 

# Install Remote Server Administration Tools if not already installed. 
if (!(Get-Module -ListAvailable -Name ActiveDirectory)) { 
    Install-WindowsFeature RSAT-AD-PowerShell 
} 

# Import the ActiveDirectory module. 
Import-Module ActiveDirectory 

#Prevent truncated output of objects in the Members array. 
$FormatEnumerationLimit = -1 

#Define the Export-CSV output location. 
$OutputFile = "$home\Desktop\Web_Filtering_Group_memberships_" + (Get-Date -Format "M.d.yyyy-HHmm") + ".csv" 

#Prevent truncated output of arrays. 
$FormatEnumerationLimit = -1 

#Discovering Security Group members. 
Get-ADGroup -SearchBase 'OU=Parent Group,OU=Security Groups,DC=domain,DC=com' -Filter * -Properties * | 
    Select-Object -Property Name, Description, GroupCategory, 
     @{Name='Members';exp={ 
      Get-ADGroupMember $_.SamAccountName | Select -ExpandProperty SamAccountName 
     }} | 
    Export-CSV -NoTypeInformation $OutputFile 

#Report end of script actions. 
Write-Output "Discovery of all Web Filtering Group members is complete. Output saved to: $OutputFile" 

Antwort

0

einfach die Mitglieder in einem kommagetrennte Zeichenfolge beitreten:

... | Select-Object Name,Description,GroupCategory,@{n='Members';e={ 
    (Get-ADGroupMember $_.SamAccountName | Select -Expand SamAccountName) -join ',' 
}} | Export-Csv ... 

Export-Csv alle exportierten Felder in doppelten Anführungszeichen setzen, so dass Sie eine Ausgabe wie diese:

"Name","Description","GroupCategory","Members" 
...,"foo,bar,baz" 
...,"some" 
...,"or,other"

Verschachtelte Kommas in Zeichenfolgenwerten sind gültige CSV-Dateien.

+0

Super! Genau das, was ich brauchte. Vielen Dank. – newyorkstateofmind