Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Passing a parameter using GET-ADUSER and failing with ParameterBindingException

$
0
0

Hi PowerShell Folks

I'm new to PowerShell and need help trying to get the following to work:

I'm currently running the following query to return me a list of user alias within a OU.

Get-Aduser -Filter 'UserPrincipalName -like "*" -and Enabled -eq "true"' -Searchbase 'OU=Accounting,DC=TEST,DC=COM' | sort-object name | Format-wide -property SamAccountName -column 1
 

I'd like to make a change and make the OU value a parameter since there are multiple groups in the environment. I can't seem to get the syntax correct using the positional option to pass in the parameter:

> test.ps1 Finance

$M = $args[0]

Get-Aduser -Filter 'UserPrincipalName -like "*" -and Enabled -eq "true"' -Searchbase 'OU='$M',DC=TEST,DC=COM' | sort-object name | Format-wide -property SamAccountName -column 1

I tried double quotes outside of "OU='$M',DC=TEST,DC=COM"

Can someone assist?

 

Thanks

Mike88

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles