Hi Everyone,
I'm not one for asking for assistance but I this one has me puzzled.
Summary
A script which imports a CSV with users, checks this imported list against an OU full of disabled users and enables and moves the users to another OU.
CSV contains the column heading "Username"
OU only contains disabled Users
This will run on a Scheduled Task each referencing a CSV which is updated each day.
Excuse for not doing this on my own.
I can usually scrape past with ugly but functional scripts doing the bare minimum it needs to get by and one of these days everything will come together and they will become things of beauty but until then ugly suits me fine.
I have had a go at pulling this together and it looks like this.
Import-Module ActiveDirectory
$GetAdminact = Get-Credential
$searchbase = "OU=DISABLEDUSERS,OU=LAB,DC=labserver,DC=com"
$ReferenceUsers = Import-Csv "C:\Folder\ReferenceUsers.csv"
$UserCount = 0
foreach ($Account in $ReferenceUsers) {
$Account.Username
Get-ADUser -searchbase $searchbase -Filter * -Identity $Account.Username -Properties Enabled | where -Property Enabled -eq $false | Enable-ADAccount -PassThru | Move-ADObject -TargetPath "OU=ENABLEDUSERS,OU=LAB,DC=labserver,DC=com"
$usercount = $usercount +1
}
This is not working and I suspect it is something to do with the -identity not being compatible with -searchbase.
I may be away down the wrong path with this but if anyone can assist I would be most grateful.
Please excuse me if I have violated any rules posting this here, I will fix any issues if pointed out.