title: Moving inactive AD computers by leveraging the lastLogonTimestamp attribute
body: <p>I am working on a Powershell script to automate AD maintenance, and  move inactive AD computers by leveraging the lastLogonTimestamp attribute from one specific OU to another in windows 2008 R2.</p>
  
  <p>However, while running the script, i keep getting the following error. I am stumped, and would appreciate any input on why this script is complaining about this.</p>
  
  <p><code>Move-ADObject : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try the command again.</code></p>
  
  <p>Below is the part of the script that throwing the above error:</p>
  
  <pre><code>### 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 "&lt;H2&gt;&lt;center&gt;Moved and disabled computers for more than 120 days&lt;/center&gt;&lt;/H2&gt;"| `
  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"
  </code></pre>