When wrapping up our PowerShell lunch and learn today, I made you guys two promises. First, I would get the notes uploaded. Second, I would copy up the 4 sample scripts that we worked with. Here is that content:
The PowerShell + AD management notes can be found here. The notes are sparse but are designed to be followed with a PowerShell console. We started our session by querying machines and ended by stringing together multiple cmdlets for some cool automation! If you have any questions (or thoughts) about the notes, drop me a comment.
At the end of our session, we dove into 4 scripts. All four scripts use the Quest AD Cmdlets. You can use the native AD module if desired.
Cleaning Up Old Computers
Our first script disables (and eventually deletes) stale computers from your domain. You will need to create an OU named Computers_Stale. If you have the AD recycle bin enabled, you can modify the script to just delete the computer instead of disabling it.
#Import Module
Add-PSSnapin Quest.ActiveRoles.ADManagement
#Disable and Move to Computer_stale
#Administration: Disable Old Computers and Move to Computers_Stale
$Computers = Get-QADComputer -SearchRoot "DC=Test,DC=local" -SearchScope Subtree -Inactivefor 366
$Computers | Set-QADComputer -Location (Get-Date)
$Computers | Disable-QADComputer
$Computers | Move-QADObject -NewParentContainer 'OU=Computers_Stale,DC=Test,DC=local'
#Delete Super Stale Computers
$Computers = Get-QADComputer -SearchRoot "OU=Computers_Stale,DC=Test,DC=Local" | where Location -GT (Get-Date).AddMonths(-7)
$Computers | Remove-QADObject
A lengthier version of this script (along with some additional instructions) can be found here.








