2016-07-31 7 views
2

아래 코드는 특정 학부모 지원 그룹의 모든 회원을 나열하기위한 것입니다. 나는 "Members"배열의 모든 값을 분리하고 그 쉼표를 CSV 출력에 포함시키고 싶습니다. 그렇게하려면 어떻게해야합니까?CSV 출력에는 쉼표가 포함됩니다.

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" 

답변

0

단순히 쉼표로 구분 된 문자열로 회원 가입 :

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

Export-Csv은 큰 따옴표로 보낸 모든 필드를두고, 그래서 당신은 얻을 것이다이 같은 출력 :

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

문자열 값의 중첩 쉼표는 유효한 CSV입니다.

+0

굉장! 정확히 내가 필요로하는 것. 고맙습니다. – newyorkstateofmind

관련 문제