Search for Disabled Users and Move to Disabled Ou using PowerShell
Created this script to search a ‘OU’ for disabled users and move them to a different ou . I have added the ‘WhatIf’ option by default .
Once you run the script it will prompt for ‘Search OU’ and ‘Target OU’ .
1 2 3 |
#Created to ease some of my daily tasks #web: http://thatlazyadmin.com #Twitter: shaun.hardneck |
1 |
Import-Module ActiveDirectory |
1 |
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') |
1 2 |
$title = 'Search Ou' $msg = 'Enter SearchOu:' |
1 2 |
$stext = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') |
1 2 |
$title = 'Target Ou' $msg = 'Enter TargetOu:' |
1 2 3 4 5 6 7 |
$ttext = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) Write-Host 'Search for Disabled Users' Get-ADUser -filter {Enabled -eq $false } -SearchBase $stext | Foreach-object { write-host 'Moving Disabled User ....' Move-ADObject -Identity $_.DistinguishedName -TargetPath $ttext -WhatIf } Write-Host 'User Object Move Completed' |
Hope this helps someone 🙂
Be First to Comment