/build/static/layout/Breadcrumb_cap_w.png

Scripting Question


Moving Devices Automatically

12/19/2019 328 views

Hi,

I need some help in creating a script which will move all devices from one OU to another OU after 1 week of domain join. 

Please assist.

Thank you in advance.

Answer Summary:
0 Comments   [ + ] Show comments

Comments


Answer Chosen by the Author

0

The command below should work as described. You would need to modify the variables as named before using.


$Date = [DateTime]::Today.AddDays(-7)
$CurrentOU = 'DISTINGUISHEDNAMEOFOU'
$DestinationOU = 'DISTINGUISHEDNAMEOFOU'
Get-ADComputer -Filter 'Created -le $Date' -Properties Created -SearchBase $CurrentOU | foreach {Move-ADObject -Identity $_.ObjectGUID -TargetPath $DestinationOU}
Answered 12/24/2019 by: Xnosis
White Belt