Moving Inactive Computers to a specified OU from Input File

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?


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:

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"

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