I am using Powershell version 5.1 on Windows 10.
I have the below code where I am trying to check the execution status, if it works then output as success else failed.
When I run the code, the code works, but it gives an output as failed.
Below is the code
if(Enable-LocalUser -Name TEST)
{
Write-Host "Success"
}
else
{
Write-Host "Failed"
}
How can I get a proper confirmation of the command execution? Please help
Enable-LocalUsercmdlet does not return ANYTHING. [grin] from the help for that cmdlet >>>OUTPUTS - None - This cmdlet does not generate any output.<<< ///// that means your IF will always test against a$NULLand$NULLcoerces to$Falsejust like zero does. ///// instead, run the cmdlet and use something like(Get-LocalUser -Name $env:USERNAME).Enabledto test if the account is enabled.