Moving Inactive Computers to a specified OU from Input File

Welcome Forums General PowerShell Q&A Moving Inactive Computers to a specified OU from Input File

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 2 months ago.

  • Author
  • #56825

    Points: 0
    Rank: Member

    Hello, I'm trying to move any inactive computers in my AD to an OU called "Disabled Computers" from an input file.
    I first created the input file by running the command:

    dsquery computer -inactive 13 >> input.csv

    I have a list of about 100 computers in this input.csv file in the format of

    How would I input this into another PowerShell command so it takes all the machines from this input.csv file and moves it to a specified file?


  • #56833

    Points: 428
    Helping Hand
    Rank: Contributor

    You don't have to use dsquery to a file and then use Powershell. Powershell can find inactive computers a couple of ways. If you have RSAT tools installed, you can you the ActiveDirectory module:

    If you want to make things easier, you can use Quest (Dell) Ad CmdLets:

    Locating obsolete users and computers

    With either tool, you would then use Move-(Q)ADObject to move the object to another OU. A basic example using the ActiveDirectory module:

    Get-ADComputer -Filter {PasswordLastSet -le @((Get-Date).AddDays(-45))} -Properties passwordLastSet |
    Move-ADObject -TargetPath "OU=Managed,DC=Fabrikam,DC=Com"
  • #56840

    Points: 0
    Rank: Member

    Hi, Rob.

    So one powershell .ps1 file and use both commands?

    $lastSetdate = [DateTime]::Now – [TimeSpan]::Parse("45")
    Get-ADComputer -Filter {PasswordLastSet -le $lastSetdate} -Properties passwordLastSet -ResultSetSize $null | FT samaccountname,PasswordLastSet

    Get-ADComputer -Filter {PasswordLastSet -le @((Get-Date).AddDays(-45))} -Properties passwordLastSet |
    Move-ADObject -TargetPath "OU=Managed,DC=Fabrikam,DC=Com"

    the first command finds inactive machines out from 45 days
    The second command will move it to a specified OU? IE: Disabled Computers

The topic ‘Moving Inactive Computers to a specified OU from Input File’ is closed to new replies.