Hi Guys,
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?
Param(
[Parameter(Mandatory = $false,Position=1)]
[string[]]$ComputerName = $env:COMPUTERNAME,
[Parameter(Mandatory = $false)]
[System.Management.Automation.Credential()]$Credential = [System.Management.Automation.PSCredential]::Empty
)
if ( 'a' -eq 'a' )
{
$Credential = Get-Credential -Message "Please provide the credentials" -ErrorAction SilentlyContinue
}
Error info - when I cancel the get-credential prompt.
PS C:\> .\draft.ps1
userName
At C:\draft.ps1:11 char:5
+ $Credential = Get-Credential -Message "Please provide the credentials" -Erro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [], RuntimeException
+ FullyQualifiedErrorId : Argument