I am trying to create a script to query AD groups to pull back the users part of that group. I can currently do it if i hard code the group into the script but i am looking to make it user interactive by allowing the user to enter the AD group the are looking for.
I have tried using Read-Host to enter the variable to pull back but it doesn't pull back no results but if i hard code it it does.
$group = Read-Host 'Please enter a AD Group!'
Get-ADGroupMember -identity '$group' -Recursive | Get-ADUser -Property DisplayName | Select SamAccountName,Name,ObjectClass
Simply change you quotes from single quotes to double quotes ( about_quoting_rules ).
$group = Read-Host 'Please enter a AD Group!'
Get-ADGroupMember -identity "$group" -Recursive | Get-ADUser -Property DisplayName | Select SamAccountName,Name,ObjectClass
The double quotes allow the Variable to be substituted. Also in this case, when passing the variable into the Get-ADGroupMember
cmdlet, quotes around the variable are not needed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.