0
votes

I have a little script that exports a certain group to a csv file.

The question is if it is possible to insert a split in the group name to export twp groups into two separate csv files.

param (
 [Parameter(Mandatory, ValueFromPipelineByPropertyname)]
 [ValidateNotNullOrEmpty()]
 [string]$GroupName
)

Get-ADGroupMember -identity “$GroupName” | select-object SamAccountName | Export-csv -path C:\Report\$GroupName.csv -NoTypeInformation 

Is it possible to write " Group1 Group2 " and the export to two files, Group1.csv and Group2.csv?

1
$a = $GroupName.trim().split(" ") will give u an array of split items. Then $a[0] will give u Group1 and $a[1] will give u Group2. So technically, you can send it to different csv - Sid
Foreach group in group, Get-ADGroupMember -identity “$GroupName” export-csv $groupname+.csv export multible files. - Kemal K.

1 Answers

0
votes

Try this:

param (
 [Parameter(Mandatory, ValueFromPipelineByPropertyname)]
 [ValidateNotNullOrEmpty()]
 [string]$GroupName
)
$allGroupNames = $GroupName -split " "
foreach( $GN in $allGroupNames ) {
    Get-ADGroupMember -identity “$GN” | select-object SamAccountName | Export-csv -path C:\Report\$GN.csv -NoTypeInformation 
}