I am trying to check a local user account if its either disabled or enabled and do the following: If enabled tell me "account is enabled, nothing to do"
If the account is disabled, tell me, Account is disabled, enabling... Enabled the account
What I get is always the first output no matter if the account is disabled or enabled:
#Checks local user if its disabled to enable it
$isEnabled = $True
$Account = 'local_account'
try {
$isEnabled = (Get-LocalUser $Account -ErrorAction Stop).Disabled
Write-output "local_account account is already enabled"
}
catch {
$isEnabled = $False
write-output "local_account account is disabled, enabling..."
Enable-LocalUser $Account