Well, now that I know I have 86 objects that have PasswordNotRequired flag I need to fix it. First let's find out who that is:
$Users = get-aduser -Filter { PasswordNotRequired -eq $True } -Properties DisplayName
$Users | Format-Table SamAccountName, Name, Enabled, GivenName, DisplayName
Now that we have that list, I want to filter out accounts that start or end with $, and few accounts that I want to leave at their defaults.
$FilterOut = @(
'IUSR_'
'IWAM_'
'Guest'
)
$UsersFilteredOut= foreach ($_ in $Users) {
if ($_.SamAccountName.StartsWith('$')) {
continue
}
if ($_.SamAccountName.EndsWith('$')){
continue
}
foreach ($Filter in $FilterOut) {
if ($_.SamAccountName.StartsWith($Filter)){
$Found = $True
break
}
}
if ($Found) {
$Found = $false
continue
}
$_
}
$UsersFilteredOut | Format-Table SamAccountName, Name, Enabled, DisplayName
Finally, if we're happy with the list, we need to set PasswordNotRequired to $false.
And you are done! Keep in mind that if Password would be indeed empty above command wouldn't work and give you an error. You would need to investigate such an account whether indeed such account should be left without a password. There are reasons that password for some account is not set, but for standard users, this shouldn't happen really. Running above code is fairly safe. As long as you won't remove WhatIf no changes will be done to your Active Directory. I would recommend trying out the first command, then working out what you need and what you don't need with a second script block, finally running fix on the users that we wanted to fix.