Moving Inactive Computers to a specified OU from Input File

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of sandy sandy 1 month ago.

  • Author
    Posts
  • #56825
    Profile photo of sandy
    sandy
    Participant

    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
    "CN=computerName,OU=x,OU=y,DC=domain,DC=com"

    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?

    Thanks!

  • #56833
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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:

    https://technet.microsoft.com/en-us/library/dd391949(v=ws.10).aspx

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

    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
    Profile photo of sandy
    sandy
    Participant

    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
    ??

You must be logged in to reply to this topic.