0

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 

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.