PowerCLI Validation Quick Scripts

I recently built a vSphere platform, and following completion of the build I was required to perform testing, and also validate that the build matched the design documents, rather than screen print a load of images for each host etc, I used PowerCLI to get the settings for me so I could compare them with the design document. I am just going to put a list of the commands, there’s nothing overly complicated or even elegant here, but they might come in handy for someone.

Get Hosts Build Numbers

Get-VMHost | Select Name,Version,Build sort-object name

Check hosts are joined to a domain

Get-VMHost | Get-VMHostAuthentication | Select-Object VMhost,DOmain,DomainMembershipStatus | Sort-Object VMhost

 Get DRS Status

Get-Cluster  Select-Object Name,DrsEnabled,DrsMode,DrsAutomationLevel

 Get Lockdown mode status

Get-View  -ViewType  HostSystem  Select
Name, @{N=“Version”;E={$_.Summary.Config.Product.Name}}, @{N=“State”;E={$_.Runtime.ConnectionState}}, @{N=“LockedMode”;E={$_.Config.AdminDisabled}} |
Where { $_.Version -match “i”} Sort-Object  Name

 Check if ESXi Shell is running on hosts

Get-VMHost Get-VMHostService  Where { $_.Key -eq “TSM”} | Select-Object VMhost,Key,Label,RUnningSort-Object VMHost

 Check is SSH Service is running on hosts

Get-Cluster | Get-VMHost | Get-VMHostService Where { $_.Key -eq “TSM-SSH”} Select-Object VMhost,Label,RunningSort-Object VMHost

 Enable SSH on all hosts

Get-Cluster | Get-VMHost | Foreach { Start-VMHostService -HostService ($_ | Get-VMHostService | Where { $_.Key -eq “TSM-SSH”} ) 


 Get Cluster HA Status

Get-Cluster | Select-Object Name,HAEnabled,HAAdmissionControlEnabled,HAFailoverLevel,HAIsolationResponse,HARestartPriority

 Get HA Reservations

Get-Cluster clustername | Select-Object Name,@{N=“CpuFailoverResourcesPercentage”;E={$_.ExtensionData.Configuration.DasConfig.AdmissionControlPolicy.CpuFailoverResourcesPercent}},@{N=“MemoryFailoverResourcesPercentage”;E={$_.ExtensionData.Configuration.DasConfig.AdmissionControlPolicy.MemoryFailoverResourcesPercent}} |
Sort-Object Name | ft -AutoSize

 Get Host Multipath policy

Get-VMHost | Get-ScsiLun | Select-Object VMhost,CanonicalName,LunType,MultipathPolicy | Sort-Object VMhost

 Get Storage IO Control Status

Get-Datastore | Select Name,StorageIOControlEnabled

 Get Scratch partition settings

Get-VMhost | Get-AdvancedSetting -Name “ScratchConfig.ConfiguredScratchLocation” | Select-Object Entity,Name,Value | Sort-Object Entity

 Check Syslog allowed through firewall

Get-VMHost | Get-VMHostFirewallException | where {$_.Name.StartsWith(‘syslog’)}

 Check vLAN Port taggings on Portgroups

$esxihosts = Get-VMHost

foreach($esxihost in $esxihosts){

Get-VirtualPortGroup -VMHost $esxihost | select $esxihost.Name,Name, VirtualSwitch, VLanId


 Check DNS Resolution for all hosts (from list of hosts in text file)

$hosts = Get-Content C:\SDCHosts.txt

Foreach ($element in $hosts){
Resolve-DnsName $element 


 Get VAAI Plugin status

Get-VMHost | Get-AdvancedSetting -Name DataMover.HardwareAccelerated*, VMFS3.HardwareAccelerated* | Select-Object Entity,Name,Value | Sort-Object Entity

 Get time server status

Get-VMHost | Sort Name | Select Name, @{N=“NTPServer”;E={$_ |Get-VMHostNtpServer}}, ` Timezone,

$_.ExtensionData.ConfigManager.DateTimeSystem) | Foreach {$_.QueryDateTime().ToLocalTime()}}}, `

@{N=“ServiceRunning”;E={(Get-VmHostService -VMHost $_ |Where-Object {$_.key-eq “ntpd”}).Running}} `

Facebooktwittergoogle_pluslinkedinby feather

Leave a Reply

Your email address will not be published. Required fields are marked *