PowerShell: Tips and Tricks

PowerShell: Tips and Tricks

WMware PowerCLI Error - Invalid Server Certificate

This is just a very common error when you trying to access the vCenter Server with PowerCLI and when you have an invalid server certificate, probably the first time you are trying to connect with PowerCLI.

PS C:\WINDOWS\system32> Connect-VIServer 192.168.89.44 -User administrator@vsphere.local
Connect-VIServer : 04.01.2021 14:30:50  Connect-VIServer                Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to connect once or to add a permanent exception for this server. 
Additional Information: Additional Information: Could not establish trust relationship for the SSL/TLS secure channel with authority 192.168.89.44.
At line:1 char:1
+ Connect-VIServer 192.168.89.44 -User administrator@vsphere.local
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Connect-VIServer], ViSecurityNegotiationException
    + FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_CertificateError,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer

PowerCLI Error - Invalid Server Certificate PowerCLI Error - Invalid Server Certificate

Just execute below command to ignore the invalid certificate:

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

source

Set-ExecutionPolicy

As a System Administrator, you can reduce sometimes a considerably amount of time by running PowerShell scripts across your Windows Systems. Most of the scripts that you find online will not run if you haven’t configured previously PowerShell, and will throw you an unpleasant error in red fonts.

Sets the PowerShell execution policies for Windows computers.

Set-ExecutionPolicy
   [-ExecutionPolicy] <ExecutionPolicy>
   [[-Scope] <ExecutionPolicyScope>]
   [-Force]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Get ExecutionPolicy

PS C:\WINDOWS\system32> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       Undefined

When you get a error like this:

PS C:\Users\rrastik> Install-Module -Name VMware.PowerCLI
Install-Module : Administrator rights are required to install modules in 'C:\Program Files\WindowsPowerShell\Modules'.
Log on to the computer with an account that has Administrator rights, and then try again, or install 'C:\Users\rrastik\Documents\WindowsPowerShell\Modules' by adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).
At line:1 char:1
+ Install-Module -Name VMware.PowerCLI
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], ArgumentException
    + FullyQualifiedErrorId : InstallModuleNeedsCurrentUserScopeParameterForNonAdminUser,Install-Module

Than you can solve this problem with:

Set-ExecutionPolicy Unrestricted

SUBSCRIBE FOR NEW ARTICLES

@
comments powered by Disqus