PowerCLI oneliners

A lot of these bits below are out-takes of relatively simple scripts I have used over time to do tasks in PowerCLI. Use at your own risk as always with scripts you find online. I will generally try to exlain a bit about the script where possible.

Getting Network Domain settings from your esxi-hosts without having to log into every host:

I came across a customer who had +300 ESXi hosts and needed to check why logging information didn’t work and one of the things we found was that not all hosts were in the same domain. The script gets the info and puts it in a CSV file for you.

get-VMHostNetwork * | select -Property VMhost, @{N=’DnsAddress’;E={$_.DNSAddress}}, @N={N=’SearchDomain’;E={$_.SearchDomain}}, @{N=’DomainName’;E={$_.DomainName}}, | Export-CSV DNS-Info.csv

 

vMotion fails due to CD stuck in drive

How often does this happen? You try to put a server into maintenance mode only to find that it doesn’t happen and when you check the vm has a cd drive (and if you are lucky it is only one). A good practice is not to leave CD’s in the drive. The below script can help with this. Keep in mind it may cause issues where the cd drive is in use (such as timeouts etc). Also since Linux needs to unmount the drive before it can eject it may cause issues.

Get-VM | Get-CDDrive | Where {$_.extensiondata.connectable.connected -eq $true} | Set-CDDrive -NoMedia -confirm:$false

 

 

%d bloggers like this: