locked
Move AD Users RRS feed

  • Question

  • I am getting the following error from running  the powershell code  below to move ad users. Can anyone help explain what i am doing wrong. I have also tested the txt file it has the correct data in there and running get -adusers -identity  grabs user information

    Import-Module ActiveDirectory
    
    $TargetOU =  "OU=user2,OU=User-V,DC=test,DC=Domain,DC=com"
    
    Get-Content C:\Users\user\Desktop\Scripts\MoveADUsers\Users.txt | ForEach-Object {
      
     $UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
    
    Move-ADObject -Identity $UserDN -TargetPath $TargetOU
     }


    Error i recieved

    Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
    At line:7 char:34
    +  $UserDN = (Get-ADUser -Identity $_.Name).distinguishedName
    +                                  ~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser

    Move-ADObject : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
    At line:9 char:25
    + Move-ADObject -Identity $UserDN -TargetPath $TargetOU
    +                         ~~~~~~~
        + CategoryInfo          : InvalidData: (:) [Move-ADObject], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.MoveADObject


      


    Monday, May 11, 2020 9:30 PM

Answers

  • This is one method that will work assuming your file contains a list a SamAccountNames.

    Get-Content C:\Users\sa400330\Desktop\Scripts\MoveADUsers\Users.txt | 
        ForEach-Object {
                Get-ADUser $_ | Move-ADObject -TargetPath 'OU=Contractors,OU=User-V-ID,DC=tsh,DC=thomson,DC=com'
        }

    I recommend that you first learn basic PowerShell and AD before trying to guess at how to do things.


    \_(ツ)_/

    • Marked as answer by Centaur1963 Monday, May 11, 2020 9:45 PM
    Monday, May 11, 2020 9:38 PM

All replies

  • Please do not post images of errors as they are completely unreadable in most browsers.  Post a full copy of the error using the code posting tool.


    \_(ツ)_/

    Monday, May 11, 2020 9:33 PM
  • Sorry i will do that
    Monday, May 11, 2020 9:38 PM
  • This is one method that will work assuming your file contains a list a SamAccountNames.

    Get-Content C:\Users\sa400330\Desktop\Scripts\MoveADUsers\Users.txt | 
        ForEach-Object {
                Get-ADUser $_ | Move-ADObject -TargetPath 'OU=Contractors,OU=User-V-ID,DC=tsh,DC=thomson,DC=com'
        }

    I recommend that you first learn basic PowerShell and AD before trying to guess at how to do things.


    \_(ツ)_/

    • Marked as answer by Centaur1963 Monday, May 11, 2020 9:45 PM
    Monday, May 11, 2020 9:38 PM
  • you are right and i am learning i assumed the logic of my command was right. thanks for the help i see from the sample script what i could do better.
    Monday, May 11, 2020 9:45 PM
  • The error message tells you that your values from the file are null.  This is because you cannot use object constructs with text files.  CSV files can be used this way.  Learning basic PowerShell will help you to understand this and why.

    The above book is free and it is one of the better ones written for techs and admins with only GUI experience.  Well written and fun to read.


    \_(ツ)_/

    Monday, May 11, 2020 10:33 PM