Hi,
You might want to think about splatting, I am working on a similar script here: New AD User automation - Make functions or not
It just makes it a bit tidier and the line where New-AdUser is will be shorter. I use a csv which
@laage recommended.
You could even do an if statement before you create the user and set the Enabled parameter to false or true depending on the age, eg.
if($temp[2] -ge $ageLimit) {
$IsEnabled = $false
} else {
$IsEnabled = $true
}
new-aduser .... -enabled $IsEnabled
Just an idea.
If you want to do it your way, then you need to to do something like this but you need to pass the User object to disable-adaccount, I haven’t tested this though
$ADuser = New-Aduser .. -passthru
$ageLimit = 75
if($temp[2] -ge $ageLimit)
{Disable-ADAccount -Identity $ADuser}
}