PowerCLI

 How to stop screen output when executing line of code?

JDMils_Interact's profile image
JDMils_Interact posted Jul 31, 2024 12:42 AM

I want to disconnect all vCenters before running my script, so I'm using this code:

Disconnect-VIServer -Server * -Confirm:$False -ErrorAction SilentlyContinue

Each time it executes I still get an error show up on the console window:

Disconnect-VIServer : 31/07/2024 2:33:29 PM	Disconnect-VIServer		Could not find any of the servers specified by name.	
At line:1 char:6
+ Disconnect-VIServer -Server * -ErrorAction Continue
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (VMware.VimAutom...Server[] Server:RuntimePropertyInfo) [Disconnect-VIServer], ServerObnFailureException
    + FullyQualifiedErrorId : Core_ObnSelector_SetNewParameterValue_ServerSpecifiedButNotFound,VMware.VimAutomation.ViCore.Cmdlets.Commands.DisconnectVIServer

Ive tried "-ErrorAction Continue" and "-ErrorAction Ignore" which present the same error message.

This line shows an error as well:

Disconnect-VIServer -Server $global:DefaultVIServers -Force

The only fix I can deduce for this is to bypass the Disconnect-VIServer command using this logic:

    If($global:DefaultVIServers)
        {
        Disconnect-VIServer -Server * -Confirm:$False -ErrorAction SilentlyContinue
        }

Is this normal?

LucD's profile image
LucD

Yes