May 02 2017 03:04 AM
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' .
#Created to ease some of my daily tasks #web: http://thatlazyadmin.com #Twitter: shaun.hardneck
Import-Module ActiveDirectory
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Search Ou' $msg = 'Enter SearchOu:'
$stext = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Target Ou' $msg = 'Enter TargetOu:'
$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 :)
Script can be downloaded from:
https://gallery.technet.microsoft.com/Search-for-Disabled-Users-49342f9e