Link to home
Start Free TrialLog in
Avatar of jbla9028
jbla9028Flag for United States of America

asked on

Powershell question on Get-ADUser

I am modifying a script and running into an issue. I have to run get-aduser and query two seperate OUs. I can't seem to get the script to pass the info the my variable right for further processing. This is what I have thus far.

#Declare Variables
$HitachiGroupDN = "CN=Hitachi-ID Exclude,OU=Security,OU=Groups,DC=company,DC=com"
$TestAccountsGroupDN= "CN= Test Accounts,OU=Security,OU=Groups,DC=company,DC=com"
$ServiceAccountsGroupDN= "CN= Service Accounts,OU=Security,OU=Groups,DC=company,DC=com"
$WombatExemptionGroupDN= "CN=Wombat Report Exemption,OU=Security,OU=Groups,DC=company,DC=com"

#Search Locations
$ou = "OU=San Diego,OU=company,DC=company,DC=com","OU=boston,OU=company,DC=company,DC=com"


$results = Get-ADUser -SearchBase $ou -Filter { memberof -ne $HitachiGroupDN -and memberof -ne $TestAccountsGroupDN -and memberof -ne $ServiceAccountsGroupDN -and memberof -ne $WombatExemptionGroupDN -and enabled -eq 'True'} -Properties  mail,GivenName,sn,Department,WhenCreated

Open in new window


when I run, I get an error that states I am passing a string to the -searchbase arguement which is not allowed. How can I get the variable $results to have the query's filters above for 2 seperate OUs?

Thank you for the help!
ASKER CERTIFIED SOLUTION
Avatar of David Sankovsky
David Sankovsky
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jbla9028

ASKER

Perfect. Thank you!