Mohammed Hamada
asked on
Create a script to move users to their pertaining AD group based on their province
Hello All,
I am trying to create a script that will add users to their pertaining group based on their province Attribute. so if the user's province attribute says "London" the script will move the user to their pertaining Organization unit.
I did the script and it worked but I want to do a generic one that will work
I would like to amend the script so that it would automatically search all the users on AD and look for the province and once it reads that it'll move the user to his City Organization Unit.
I'd appreciate any thoughts.
Thanks
I am trying to create a script that will add users to their pertaining group based on their province Attribute. so if the user's province attribute says "London" the script will move the user to their pertaining Organization unit.
I did the script and it worked but I want to do a generic one that will work
Get-ADuser -SearchBase "DC=Opera,DC=com" -properties * -Filter * | Where-Object {$_.st -like "London"} | Move-ADObject -TargetPath "OU=London,OU=UK,OU=DOB USER,DC=Opera,DC=com"
I would like to amend the script so that it would automatically search all the users on AD and look for the province and once it reads that it'll move the user to his City Organization Unit.
I'd appreciate any thoughts.
Thanks
ASKER
Hi Mcsween, that didn't work it asked for the identity. I was trying to use where-object instead for-each but that didn't work either however it didn't give me any error .
Get-ADuser -SearchBase "DC=opera,DC=com" -properties * -Filter * | Where-Object "$OU={$_.st}" | ForEach-Object {Move-ADObject -TargetPath "OU=$OU,DC=opera,DC=com"}
ASKER
I am sure I can do this with If statement but my problem is that I am not good yet with scripting.. I would say If user's State is Bavaria and province is Munich then move user to OU=Munich,OU=Bavaria..etc
Else if user's state is London and his province is Greater Manchester then move user to OU=Greater Manchester, OU=London"
Else if user's state is London and his province is Greater Manchester then move user to OU=Greater Manchester, OU=London"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot
Open in new window