I'm trying to use PowerShell to search AD for Group Names.
Why don't either of these work, the param or the Read-Host
? Both are passing strings, but the results are empty. However, if I replace the variable $ADGroup
in the command with an actual Group Name (a string) and run the command Get-ADGroup...
results are provided as expected. I tried to replace the double quotes with single quotes and I get the same results, the command works alone but neither Read-Host
or param provide information. I can't figure out why the string isn't being passed when it's a variable ($ADGroup
). Thanks.
param(
[Parameter(Mandatory=$true)]
[string]$ADGroup
)
# One or the other param or Read-Host
$ADGroup = Read-Host "Enter Group Name"
PS \> Get-ADGroup -Filter {name -like "*$ADGroup*"} -Properties * | Select-Object -Property Name
Get-ADGroup -Filter {name -like '*GroupName*'} -Properties * | Select-Object -Property Name
Name
----
Results
Results
Results
Results
Results