# Setup input and output files $Input = "C:\grps.csv" $Output = "C:\grps_output.csv" # Load the AD module so we can access AD information Import-Module ActiveDirectory # Load our input file - a CSV with one column of Group names with a header "Samaccountname" $GroupList = Import-Csv “C:\grps.csv” # Loop through the list of groups $GroupList | ForEach-Object { # Append the member of the current group to $Data $Data = Get-Adgroup $_.SamAccountName | select-object Name $Member = Get-Adgroupmember $_.SamAccountName | select-object Name } # $Data now has a full list of users from each group # Dump $Data out to a CSV file $Data, $Member | Export-CSV $Output -noType
the above code only uses the first group in the list. Also, it does not run both commands successfully together. They work individually. very new to powershell. my goal is to have 1 column with the name of the group and the second column with the users in that group for all groups listed in the file. any help would be appreciated.
Matt