Found a lot of scripts out there that do the same thing but since I spent a little time on this I'd like to understand why it doesn't work.
I wrote a script that finds all Inactive computer objects in AD, moves the objects to a "Inactives" OU, and then disables them.
$computers = dsquery computer -inactive 12 -limit 0
Foreach ($computer in $computers)
{
Move-ADObject -Identity $computer -TargetPath "OU=Inactives,OU=Harmony Computers,DC=scnutr,DC=local"
}
$inactives = Get-ADObject -LDAPFilter "(objectClass=computer)" -SearchBase "OU=Inactives,OU=Harmony Computers,DC=scnutr,DC=local"
Foreach ($inactive in $inactives)
{
dsmod computer $inactive -disabled yes
}Everything works except the Move-ADObject command. It returns and object not found error:
Move-ADObject : Cannot find an object with identity: '"CN=PC-W7-X32,CN=Computer
s,DC=scnutr,DC=local"' under: 'DC=scnutr,DC=local'.
At C:\Temp\InactivePC.ps1:7 char:14+ Move-ADObject <<<< -Identity $computer -TargetPath "OU=Inactives,OU=Harmony
Computers,DC=scnutr,DC=local"+ CategoryInfo : ObjectNotFound: ("CN=PC-W7-X32,C...cnutr,DC=loca
l":ADObject) [Move-ADObject], ADIdentityNotFoundException+ FullyQualifiedErrorId : Cannot find an object with identity: '"CN=PC-W7-
X32,CN=Computers,DC=scnutr,DC=local"' under: 'DC=scnutr,DC=local'.,Microso
ft.ActiveDirectory.Management.Commands.MoveADObjectMy DSquery command returns a DN which includes my domain name but the Move-ADObject command is already looking there. Not sure how to fix. Any help or insight would be appreciated :)