none
Move Computers from Text File to OU - PowerShell RRS feed

  • Question

  • I have a text file in the following format:

    Computer01

    Computer02

    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

Answers

  • 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