Apologies if this is a silly question. I have the below sample code which will prompt for the credentials. When I run this, if I cancel the get-credential prompt, why is it throwing an error and how to suppress that?
Thanks Don, Actually in my original script I prompt for the credential if the currently logged on user is not a domain user and also if the user hasn't selected the credential parameter. .
if ( $ComputerName -ne $env:COMPUTERNAME -and $env:USERDOMAIN -ne $domain -and $Credential.UserName -eq $null )
$Credential = Get-Credential -Message "Please provide the credentials to be used to be used for remote connection" -ErrorAction SilentlyContinue