Move Computers from Text File to OU - PowerShell RRS feed

  • Question

  • I have a text file in the following format:



    I'm trying run this PowerShell Script against it that moves any computer name in the file over to the Dormant OU in our environment:

    Import-module ActiveDirectory

    $computerObjects = get-content C:\ComputerNames.txt

    ForEach($computerObject in $computerObjects)

    {Move-ADObject $computerObject -TargetPath "OU=Dormant, DC=company, DC=com"}

    When I run it, I get the following error message:

    "Move-ADObject : Cannot find an object with identity: 'Computer1' under: 'DC=company,DC=com'."

    Can you provide some insight on the situation?  Thanks!

    Monday, April 14, 2014 9:54 PM


  • This will work better.

    get-content C:\ComputerNames.txt | Get-AdComputer -ea 0 | Move-AdObject -TargetPath 'OU=Dormant, DC=company, DC=com'


    • Edited by jrv Monday, April 14, 2014 10:19 PM
    • Marked as answer by section8network Monday, April 14, 2014 11:01 PM
    Monday, April 14, 2014 10:16 PM