Avatar of Jaber MM
Jaber MM
 asked on

script to move computer from default OU to named OU

hi all,

any one can have any idea how to move computer from default OU to named OU using power shell command .

for example UComputer is the new OU

mostly the script will work on the first letter of the computer name i.e. U for Ucomputer Container , M for MComputer Container

appreciate your help and support .
PowershellActive DirectoryDomain Controller

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon
Patrick Bogers

get-adcomputer computerName | Move-ADObject -TargetPath ‘ou=Ucomputer,dc=domain,dc=net’

Cheers
Jaber MM

ASKER
@Patrick Bogers

thanks for your fast reply , so i need to have three of this for each OU

get-adcomputer computerName | Move-ADObject -TargetPath ‘ou=Ucomputer,dc=domain,dc=net’

where i can put the computer name to specify that it is start with a C or M letter

according to what i understand this script will move the computer based on the full name and what i need to move based on first letter

thanks
Patrick Bogers

Get-ADComputer -Filter {name -like "C*"}

Run this to test if it is desired return. If so append
| Move-ADObject -TargetPath ‘ou=Ucomputer,dc=domain,dc=net’     To it.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Shaun Vermaak

Just curious, why not just permanently redirect
redircmp.exe "OU=Our Computers,DC=Domain,DC=com"

Open in new window

ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
oBdA

Full solution provided.

https:#a42095427 doesn't move from the default Computer container, and it doesn't support the required "move multiple computers to different OUs based on their names" mapping.

@Shaun:
that won't work in this case, because the target OU needs to be determined dynamically based on the computer name.