Hi Guys ,
For those of you wanting to automate the decommission of servers or desktops or users you can use the following powershell script or runbook for disabling the AD account provided the service account has the rights to do disable the AD account and then move the account to the desired OU location ..
Once you create the runbook it will look like the following screenshot . You can use the powershell script which i have given at the bottom of the blog .
In the invoke activity for task , input the target OU which you want to move the disabled AD computer to.
The powershell script is as follows :
$error.clear()
powershell{
try {
$Env:ADPS_LoadDefaultDrive = 0
Import-Module ActiveDirectory
$cmp=get-adcomputer -Filter { name -like “\`d.T.~Ed/{CD8776D9-08B1-4DA0-9A25-CDC65F8EBCAE}.{A7FA4C4E-F516-43AA-8093-861C6BF6FCA8}\`d.T.~Ed/”}
$cmp | set-adcomputer -enabled 0
$cmp | Move-ADObject -TargetPath “\`d.T.~Ed/{CD8776D9-08B1-4DA0-9A25-CDC65F8EBCAE}.{D455F216-D88C-4849-82B9-A5649B44481E}\`d.T.~Ed/”
} catch {
$errormessage= $_.Exception.Message
}
}
if ($error.count -gt 0) {
$result=$error[0].exception
} else {
$result=”success”
}
Hope this blog helps you . Stay tuned for more run-books 🙂
Leave a Reply