Hi,
Scratching my head right now about error wrapping/handling for "Disconnect-VIServer" while connecting/disconnecting to/from ESXi host (yes, yes, not vCenter but ESXi host).
Basic command is as below:
$disconnect = Disconnect-VIServer -Server <targetVMHost> -Confirm:$false
So it seems that I'm able to get 2 types of error for now out of that above command.
1. "Could not find any of the servers specified by name"
Disconnect-VIServer: C:\Users\pp\Desktop\project\script.ps1:54:19
Line |
54 | … isconnect = Disconnect-VIServer -Server "test" -Confirm:$false -Force …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 1/22/2024 10:03:44 AM Disconnect-VIServer Could not find any of the servers specified by name.
2. "Cannot validate argument on parameter 'Server (...)'."
Disconnect-VIServer: C:\Users\pp\Desktop\project\script.ps1:54:47
Line |
54 | … $disconnect = Disconnect-VIServer -Server $targetVmHost_DEBUG -Confir …
| ~~~~~~~~~~~~~~~~~~~
| Cannot validate argument on parameter 'Server'. The argument is null or empty. Provide an argument that is not null or empty, and then try the
| command again.
As far as I can see adding "-WarningAction SilentlyContinue -ErrorAction SilentlyContinue" doesn't really change anything.
Also $disconnect is $null in both cases and there is nothing inside "$Error[0]".
Something is not working as expected? How should I handle this?