I'm new to powershell and trying to use the try/catch command in handling the error message.
$Output = Invoke-SqlCmd -ServerInstance $dbinstance -username $dbusername -password $dbpassword -Database $dbname -Query $Query
$isconnected = ''
if ($Output.uri -eq '0' ) {
$isconnected = $true
Write-Host -Foreground Green $isconnected
}else {
$isconnected = $false
Write-Host -Foreground Red $isconnected
}
This is the error I get, but the result remains true even though the outcome should be error because I'm trying to figure out how to catch the error.
