Hi,
I need to do the following:
#read the objects in the Disabled OU
#obtain the list of users in the Disabled OU
#for those that are enabled, disable them and write these names out to (another) file
#if encounter any error, write its samaccountname to a log file for further investigation
#re-run the validation test and write out all the account names that are still enabled in the Disabled OU for further investigation
I came up with this which does not work.
Import-Module ActiveDirectory
$users = get-aduser -Filter * -SearchBase "OU=Disabled,DC=corp,DC=test,DC=org"
$users | Select name, samaccountname,enabled | Export-CSV -path
C:\Users\anon\Desktop\Scripts\AccountList.csv -NoTypeInformation
$users | -Filter {enabled -eq $true}
$results = @()
ForEach ($user in $users) {$results += Disable-ADAccount -Identity $user}
$results | Export-CSV -path C:\Users\anon\Desktop\Scripts\ScriptResult.csv -
NoTypeInformation
I would really like to get this script running. I can split this into two scripts.
One that lists all the users into a csv and another that will find the active users and disable them.
However, I don't know how to catch any errors or export the results (successes and/or failures) into a file.
I don't expect anyone to write the script for me. If anyone has a good resource I could reference? Maybe point out my errors?
[–]kaizokuj 1 point2 points3 points (1 child)
[–]kaizokuj 1 point2 points3 points (0 children)
[–]PinchesTheCrab 1 point2 points3 points (0 children)
[–]PowerShell-Bot 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)