I want to get a list of group names from AD, then provide that list to the user, so they can select the appropriate group and get a list of its members.
Import-Module ActiveDirectory Get-ADGroup -Filter {name -like 'XXX XXX*'} | sort name | select name $Prompt = Read-Host -Prompt 'Enter Mailing List Name(without XXX XXX)'; $MailingList = "YYY YYY $Prompt" $Path = 'O:\ADGroups\Mailing Lists\' Get-ADGroupMember -Identity $MailingList -Recursive | sort lastname | select name,SamAccountName | Export-csv "$path$MailingList.csv" -NoTypeInformation
If I just type “Get-ADGroup -Filter {name -like ‘XXX XXX*’} | sort name | select name” I get a list, but when I try to put it into a script, it just goes right to the prompt for the selection.
What am I overlooking?