Category: PowerCLI

PowerCLI Update Fails on Certificate Issue

Today I was updating my PowerShell modules on my local system but I ran into an issue related to certificates. After some investigation, it appeared that the PowerCLI Update was failing. Every PowerCLI module that it tried to update returned an error and did not update to a newer version. In this blog post, I am showing you how to get rid of this error and you will be able to update PowerCLI again to the latest version.

Environment

Here is a quick summary of my environment where the issue occurred:

  • Current PowerCLI: 12.1.0.16997004
  • The system tried to update PowerCLI to: 12.4.0.18627054
  • Operating System: Windows 10 Pro (21H1)

Problem

Here is an overview of the PowerShell command I used to update my modules. Also, the error message is listed below in the code box. As you can see PowerShell is complaining about a DigiCert certificate and that it is not save to update because of the certificate change.

# Open a PowerShell command prompt with administrative permissions

# Enter the command to update the PowerShell modules
Update-Module

# The following error message appears
Install-Package: Authenticode issuer 'CN=DigiCert Trusted Root G4, OU=www.digicert.com, O=DigiCert INc, C=US' of the new module 
'VMware.VimAutomation.Sdk' with version '12.4.0.18627054' is not matching with the authenticode issuer 'CN=VeriSign Class 3 Public Primary Certification 
Authority - G5, OU="(c) 2006 VeriSign, Inc. - for authorized use only", OU=VeriSign Trust Network, O="VeriSign, Inc.", C=US' of the previously-installed
 module 'VMware.VimAutomation.Sdk' with version '12.1.0.16997004'.

Here is a screenshot of the error message, error message is listed in red text. It also shows the commands I used for the PowerCLI update on my local system.

Solution

The solution for fixing the issue is quite simple. Just reinstall the VMware PowerCLI modules on your local system. This needs to be done in a forced way but after that, you are done.

# Open a PowerShell command prompt with administrative permissions

# Enter the command to re-install the PowerShell modules
Install-Module VMware.PowerCLI -Force -SkipPublisherCheck

# Wait a couple of minutes and everything should be upgraded.
Get-Module -ListAvailable VMware.PowerCLI | Select-Object Name, Version

As you can see in the screenshots below the PowerCLI update is working and is returning no errors after the upgrade.

Wrap-up

This wraps up this small blog post about a PowerCLI update issue in PowerShell. Thank you for reading and I hope it helped you out. Please respond in the comment section below if you have any questions or remarks!

PowerCLI 10.0.0 – Error Invalid Server Certificate

Overview

On the 28 of February VMware PowerCLI 10.0.0 was released. The biggest change in this release is the multi-platform support which includes the support for Mac OS and Linux. Oh and they kind of increased the version number a bit… from 6.5.X to 10.0.0 ;).

So I decided to upgrade PowerCLI in my Lab environment. In my Lab environment, I have a Windows 10 virtual machine that runs as an Administrator Workstation. The upgrade was very smooth and it took about one minute but after the upgrade, no connections were possible with my vCenter server.

The following error was displayed in the PowerShell prompt, screenshots are displayed below:
Error: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt exception for this server.

It appears that they have changed the default PowerCLI behaviour regarding certificates.

PowerCLI 6.3 – Start-VM Exception has been thrown by the target invocation.

Today I was running one of my favourite home lab scripts to startup and shutdown my lab environment. Sadly, this ended with a PowerCLI error code. So it was time to investigate what was going wrong because the code did not change but the script stopped functioning at some point.

Error message:

The first thing we look at is the error message. The following error message was displayed inside my PowerCLI console:
“Start-VM Exception has been thrown by the target invocation”

So it appears the command “Start-VM” is causing some issue. The Start-VM PowerCLI cmdlet is responsible for sending a command to vCenter Server to start a particular virtual machine.

Fix:

The first thing I noticed the system I was using was not running the most recent version of PowerCLI. So the first thing I did was upgrade PowerCLI from version 6.3 to PowerCLI version 6.5. I rebooted the system and I started the script again. It appeared that all the problems were gone :). So something surrounding the “Start-VM” cmdlet is not working correctly in PowerCLI 6.3. I could not find any information or a changelog entry related to the issue but it fixed “something” :).

Screenshots:

The first screenshot displays the script and encountering the issue with PowerCLI version 6.3. The second screenshot the same script is run but with an installed PowerCLI 6.5 version. As you can see the issue is resolved now.

PowerCLI 6.3 - Start-VM Exception has been thrown by the target invocation
PowerCLI 6.3 – Start-VM Exception has been thrown by the target invocation

PowerCLI 6.5 - Start-VM problem solved
PowerCLI 6.5 – Start-VM problem solved

PowerCLI Datastore Selection without Storage DRS (SDRS)

When deploying some virtual machines in a test environment I ran into the following problem. In most cases, I make use of a VMware vCenter Storage DRS cluster, in this case when deploying a virtual machine the best-suited datastore is selected for the virtual machines. The only problem is not all customers are entitled to use Storage DRS, because Storage DRS requires a vSphere Enterprise Plus license.

So I needed to create a workaround to select a datastore with enough space. The default PowerCLI behavior is selecting the first datastore detected on a alphabetic order.

So when you are deploying let’s say twenty virtual machines all those virtual machines will be put on the first datastore, so that isn’t going to work well in most cases.



PowerCLI Code

To solve the problem I created the following PowerCLI code. The code selects a cluster and lists all the datastore available. The datastore with the most space available is selected for the virtual machine that is being deployed.

In the PowerCLI code, I just create a very simple virtual machine but you probably get the point. The magic is the $DS line that selects the datastore.

Requirements:

The PowerShell code is tested with the following VMware software components on Microsoft Windows:

  • PowerCLI 6.5 Update 1
  • VMware vCenter Server 6.0
### Variables
$CLUSTER = "Production"       # A Cluster Name
$FOLDER = "Deployed VMs"      # A Virtual Machine folder name located in the vCenter inventory

### Select datastores available and sort them on free space (select the one with most space free)
$DS = Get-Cluster -Name $CLUSTER | Get-Datastore | Select Name, FreeSpaceGB | Sort-Object FreeSpaceGB -Descending | Select -first 1

### Create a virtual machine called VM01
New-VM -Name VM01 -ResourcePool $CLUSTER -Datastore $DS.Name -Location $FOLDER -MemoryGB 1 -CD -DiskGB 5

Article update:

  • 2018-07-30 – Added feature image.
  • 2018-11-17 – Updated article to support the new standards of the website.