The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

goldfinger (9) [Avatar] Offline
#1
Is there a way to catch the error "Logon failure: unknown user name or bad password"?

# Trap is not working if user name or password is wrong
$ProgsArgs = "TimeDate.cpl"
$computer= $env:Computername
$cred = Get-Credential
TRAP {"Can't logon"; continue}
[void] [System.Diagnostics.Process]::Start("control.exe",$ProgsArgs, $cred.username, $Cred.password, $computer)

Exception calling "Start" with "5" argument(s): "Logon failure: unknown user name or bad password"
At line:1 char:43
+ [void] [System.Diagnostics.Process]::Start( <<<< "control.exe",$ProgsArgs, $cred.username, $Cred.password, $computer)
goldfinger (9) [Avatar] Offline
#2
Re: Trap and Logon failure
I solved the problem. I tried the above code in interactive mode. Using a powershell script file instead is working fine.