PowerCLI error – Invalid server certificate

On client systems with fresh PowerCLI installations I often get an error when trying to run scripts.

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

The reason is that PowerCLI refuses to run scripts with invalid certificates. If you’re running your own scripts, you can switch off that feature.

Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

Enable SSH cluster-wide with PowerCLI

This article shows how to quickly enable SSH service on one, more or all hosts in a cluster.

Start service

Login to vCenter.

Connect-VIServer <myVC>

The command below will activate SSH on all hosts registered in in your vCenter.

Get-VMHost | Get-VMHostService | Where Key -EQ "TSM-SSH" | Start-VMHostService

TSM means “Technical Support Mode”

Stop SSH service

To stop SSH service on all hosts, use the command below.

Get-VMHost | Get-VMHostService | Where Key -EQ "TSM-SSH" |  Stop-VMHostService -Confirm:$False

Selective activation

It’s possible to limit the scope of the command to one host. Just add the FQDN after Get-Host.

Get-VMHost myESX.myDomain.local | Get-VMHostService | Where Key -EQ "TSM-SSH" | Start-VMHostService

Find VMs without tags

Check Backup-Tag SLA

VMware tags are a versatile tool to dynamically assign VMs to groups. One use-case is leveraging VM-Tags to guarantee backup-SLA. Im my case there’s a category named “Backup” which contains several backup SLA tags for weekly or daily backups.

Oneliner

With PowerCLI you can find out quickly which VMs have no tags.

connect-viserver myVC
get-vm | ?{ (get-tagassignment $_) -eq $null}

This query isn’t sufficient yet. It’ll report only VMs that have no tags at all. But we’d like to find VMs that have no tags from the category “Backup”. So we have to modify our query a little bit.

get-vm | ?{ (get-tagassignment $_ -category Backup) -eq $null}

You need to adjust your query with the corresponding category name.

 

Backup and Restore of ESXi host configurations with PowerCLI

I’m a big fan of PowerCLI one-liners. 🙂

Before performing updates, upgrades or any other maintenance on ESXi hosts, you should backup your ESXi host configuration. Setting up a new ESXi host as replacement is a no-brainer, but rebuilding a lost configuration can be a PITA and might take hours.

In the old times it was necesary to open a SSH shell connection or to use vSphereCLI to issue backup commands to ESXi hosts. Recently I realized that there is a very handy PowerShell commandlet to backup and restore the configuration. Continue reading “Backup and Restore of ESXi host configurations with PowerCLI”