title: Powershell - Disable and move users to a new OU
body: <p>brand new member here..</p>
  
  <p>I'm trying to create a powershell script that can create a new OU with the current date (dd-MM-yyyy), disable users from a text file and then move them to the newly created OU. </p>
  
  <p>So far I have gotten everything but the move to work. I've read that it might be because the text file contains the users <code>sAMAccountName</code>, which doesn't work with <code>Move-ADObject</code>? </p>
  
  <p>Just for the record I'm pretty new to scripting in general, and I know the last line is completely off. Everything has been composed of stuff I have found online.</p>
  
  <p>Code:</p>
  
  <pre><code>$OU = "$((get-date).toString('dd-MM-yyyy'))"
  $PathOU = "OU=DEPARTURES,OU=IT,OU=USERS,OU=DK,DC=xxx"
  
  New-ADOrganizationalUnit $OU -ProtectedFromAccidentalDeletion $false -Path $PathOU
  
  $CN = get-content "\\Server\User Administration\User Deletion\UsersToBeDisabled.txt"
  $CN |Foreach {
  Get-ADUser $_ | Disable-ADAccount
  Move-ADObject -Identity $_ -TargetPath $OU
  }
  </code></pre>
  
  <p>Error:</p>
  
  <blockquote>
    <p>Move-ADObject : Cannot find an object with identity: 'firstname.lastname' under: 'DC=xxx'.
    ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.MoveADObject**</p>
  </blockquote>
  
  <p>I hope you have some ideas on how to get this to work, thanks!</p>
  
  <p>BR. Mik</p>