Hi LucD,
I want use this with the script before I start, I wanted to disconnect the previous sessions if any, so When I tried the suggested command, I am getting the error as below

Is there a way to check if we are connected to vcenter without using connect-viserver command and like to disconnect it before I connect to different vcenter from script
where if the session is connected, it should disconnect, or if the session is not connected, it should exit
please help
function dis {
$vc = connect-viserver "aurvpvcntrapp01"
if($vc.IsConnected)
{
Write-host "Connected To : $vc"
Disconnect-VIServer $vc -force -Confirm:$false -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
}
else
{
exit
}
}
dis