This script will be useful if you want to move computer objects in the Active Directory filtered by name to a destination OU
Script :
$computerstomove = Get-ADComputer -LDAPFilter "(name=Desktop00*)" -SearchBase "CN=computers,DC=domain,DC=local,DC=net" foreach ($computertomove in $computerstomove) { Move-ADObject $computertomove -TargetPath "OU=DestinationOU,DC=domain,DC=local,DC=net" }
Move-ADObject
Moves an Active Directory object or a container of objects to a different container or domain.
Syntax
Move-ADObject [-Identity][-TargetPath] [-AuthType { | }] [-Credential ] [-Partition ] [-PassThru] [-Server ] [-TargetServer ] [-Confirm] [-WhatIf] [ ]
- Identity
- TargetPath
- AuthType
- Credential
- Partition
- PassThru
- Server
- TargetServer
- Confirm
- WhatIf
Detailed Description
The Move-ADObject cmdlet moves an object or a container of objects from one container to another or from one domain to another.
The Identity parameter specifies the Active Directory object or container to move. You can identify an object or container by its distinguished name (DN) or GUID. You can also set the Identity parameter to an object variable such as $
The TargetPath parameter must be specified. This parameter identifies the new location for the object or container.
Thanks for the script and its working fine.
Its fulled my requirement.
What if we have a multiple TargetPath?
Hello izzi,
Could you please give me more information on what you want to do ? The current script parse a list of computers and move them one by one to the path indicated in the parameter TargetPath. If you need more than one Targetpath, you will need to set an array with the computer names and for each of them, the targetpath you want.
Tell me if you need help…
Could you please confirm whether the above would also work if we want to move the computer object from an existing OU to a new AD group.
Hello Priyank,
No the current script is not right solution to achieve your goal. Contact me by email user01062008@shellandco.net if you want help to write this script
Cheers
Nico
This sorted out an issue we were facing. Thank you very much
Hi Nicholas
How can we do modify script to do below things?
1. Query AD for computer name beginning with “ABC-” and move them to OU “ABC”
2. Query AD for computer name beginning with “DEF-” and move them to OU “DEF”
We have group policy that’s unique for each OU.
Visan