Hello,
I'm refining my script and trying to handle errors and write nice error messages. But somehow the catch of an specifiy error will not work.
Here's my code:
try {
Connect-VIServer -Server $serverconfig.vCenterServer -ErrorAction Stop
}
Catch [VMware.VimAutomation.ViCore.Types.V1.ErrorHandling.InvalidLogin] {
Write-Host "Wrong Credentials"
$vmcheck = 1
}
try {
Disconnect-VIServer * -Confirm -ErrorAction Ignore
}
catch [VMware.VimAutomation.ViCore.Cmdlets.Commands.DisconnectVIServer]{
write-host "no connections to disconnect"
}
try {
Disconnect-VIServer * -Confirm -ErrorAction Ignore
}
catch [VMware.VimAutomation.ViCore.Cmdlets.Commands.DisconnectVIServer]{
write-host "no connections to disconnect"
}
what am I doing wrong? How should I handle these kind of error?
Thanks and best
Noah