Ich arbeite an einem Powershell-Skript zur Automatisierung der AD-Wartung und zur Verschiebung inaktiver AD-Computer mithilfe des Attributs lastLogonTimestamp von einer bestimmten Organisationseinheit in Windows 2008 R2.Verschieben von inaktiven AD-Computern mithilfe des lastLogonTimestamp-Attributs
Beim Ausführen des Skripts bekomme ich jedoch immer den folgenden Fehler. Ich bin ratlos und würde mich über jeden Beitrag freuen, warum dieses Skript sich darüber beschwert.
Move-ADObject : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try the command again.
Unten ist der Teil des Skripts, dass die obigen Fehler werfen:
### Find and all inactive computer objects
import-module activedirectory
$domain = "XXXXX.XXXXX.XXXXX"
$DaysInactive = 120
$time = (Get-Date).Adddays(-($DaysInactive))
$pwdset = (Get-Date).AddDays(-($DaysInactive))
### Get all AD computers with lastLogonTimestamp less than our time
$OldComputers = Get-ADComputer -Filter {LastLogonTimeStamp -le $time} -Properties lastlogontimestamp |
Where-Object {
$_.DistinguishedName -like "OU=Source OU,DC=XXXX,DC=XXXX,DC=XXXX"
}
## Output computer accounts to be disabled to HTML table
$OldComputersLog = $OldComputers | ConvertTo-HTML lastlogontimestamp `
-title "Computer Accounts that will be deleted" `
-head $head `
-body "<H2><center>Moved and disabled computers for more than 120 days</center></H2>"| `
out-file C:\AD\move\OldComputers.html
### Move inactive computers to disabled OU
$OldComputers | Disable-ADAccount |Move-ADObject -TargetPath "OU=Destination OU,DC=XXXX,DC=XXXX,DC=XXXX"