foreach($U in (Get-LocalUser -name test*|Where-Object{$_.Enabled -eq 'true'}))
{
if(Disable-LocalUser -name $u.name -ErrorAction stop){ "Success"
Write-Output "User $($u.name) disabled" |out-file C:\Windows\Temp\Disable.log -Append}
else{"Failure"
Write-Output "User $($u.name) could not be disabled" |out-file C:\Windows\Temp\Disable.log -Append}
}type or paste code here
Hi there,
i am trying to do this basic error correction/logging just in case the command failes to disable any accounts it finds for whatever reason.
the command itself works fine but always reports “Failure” by the “if” statement and i think its something about the output of that command which is interperted as “not true”
any help/feedback is welcome(i already made it work with try/catch but more interested on why it didnt work with “if”)
Thanks