PowerShell Script for Computer Objects

Hello,

Can someone tell me what I'm missing here...

I'm working on a script to move disable computer object to the disable computer OU. 

Here's one of my scripts:

Import-Module ActiveDirectory
$computer = get-adcomputer | where {$_.lastlogondate -lt ((get-date).adddays(-90))}
Move-ADObject $Computer.ObjectGUID -TargetPath "OU=DisabledComputers,DC=domain,DC=com"

another:

Import-Module ActiveDirectory
Get-ADComputer ComputerDisabled ComputersOnly | ?{ $_.DistinguishedName -match 'OU=Computers,'} | Move-ADObject TargetPath OU=Disabled Computers,DC=axiallcorp,DC=com

Thank you

August 18th, 2015 4:11pm

I am not much of a powershell scripter in any sense but would the below work for you?

import-module activedirectory $domain = "domain.com" $DaysInactive = 90 $time = (Get-Date).Adddays(-($DaysInactive)) Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | Move-ADObject -TargetPath "OU=DisabledComputers,DC=domain,DC=com"


Free Windows Admin Tool Kit Click here and download it now
August 18th, 2015 5:11pm

Hi MaxJ15,

Thanks for your post.

You could refer to the article about list and move computer objects.

http://social.technet.microsoft.com/wiki/contents/articles/5819.ad-powershell-for-active-directory-administrators.aspx

In addition, you could also post in PowerShell Forum for more support.

https://social.technet.microsoft.com/Forums/windows/en-US/home?forum=winserverpowershell

Best Regards,

Mary Dong

August 19th, 2015 3:02am

You can download the complete PS command from below mentioned technet resource. Please modify according to your need and apply the same : https://gallery.technet.microsoft.com/scriptcenter/Move-and-disable-inactive-b1cf86c3

If the PS command does not helps you much, you may consider on our Lepide active directory cleaner tool that helps to obsolete inactive accounts and manage them through automated actions i.e. reset password, delete, disable and move inactive accounts to another OU.

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 3:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics