Moving AD Computer Object with Powershell


Moving AD Computer Object with Powershell

A computer object in powershell is represented by
TypeName: Microsoft.ActiveDirectory.Management.ADComputer.
ADComputer has a property “DistinguishedName”. At time of writing this Microsoft.ActiveDirectory.Management.ADComputer has no methods to change this value. Use Move-ADObject to change its location in AD.

An AD Orginizational Unit is represented by
TypeName: Microsoft.ActiveDirectory.Management.ADOrganizationalUnit.
It has a property of “DistinguishedName”

Using Move-ADObject

What you require.

  • Computer Name String
    “Computer127”
    OR
    Microsoft.ActiveDirectory.Management.ADComputer Object
  • Orginizational Unit/DistinguishedName String
    “OU=Servers,DC=PAULLIGOCKI,DC=COM”
    OR
    Microsoft.ActiveDirectory.Management.ADOrganizationalUnit Object

Example 1:

Get-ADComputer "Computer127" | Move-ADObject -TargetPath "OU=Servers,DC=PAULLIGOCKI,DC=COM"

Example 2:

$ComputerToMove = Get-AdComputer "Computer127"
$DestinationPath = Get-ADOrganizationalUnit -Identity "OU=Servers,DC=PAULLIGOCKI,DC=COM"
$ComputerToMove | Move-ADObject -TargetPath $DestinationPath.DistinguishedName
,