I've been given a task that would be perfect for Powershell, and have taken the opportunity to learn the Powershell scripting language.
I have a CSV file with two colums:
Name, Active
I want to grab the name of each record that has disabled in the column. With that name, I want to check the AD and check if they're disabled or not. Ultimately, if they're not disabled, I want to disable them but I don't want you guys to spoil all of the fun for me!
Here's where I am at, I don't know if the following is possible but as it is right now there are syntax errors.
$file = 'C:\scripts\users.csv'
$test = Import-CSV $file | Where-Object {$_.Active -like "disable*"} | Select-Object Name
foreach($user in $test){
if (Get-AdUser -LDAPFilter "(samaccountname=*$user*)" | Select-Object Enabled){
Write-Host $user + "is active"
}
}
Thanks for any help.
Edit: I've fixed the syntax error, and now the Script will run but there is no output. I know that there are users that are still active, so there should definitely be some output.