PowerCLI One Liners

I have come across various powercli one liners as I work with vSphere that are helpful for quickly collecting information. Some of these come from blogs or the VMware communities pages, thanks to all those contributors! 

This will list the details of RDMs for a VM (very useful if you have many gatekeepers for example):

get-vm -name [VM Name] | get-harddisk -disktype “RawPhysical”,”RawVirtual” | select Parent,Name,DiskType,ScsiCanonicalName,DeviceName | fl

 

This will list VM mapping to physical vmnic:

Connect-viserver [hostname]

Get-EsxTop -CounterName NetPort | Select PortID, ClientName, TeamUplink

 

This will get your host DNS settings (Primary / Secondary DNS servers):

Get-VMHost [hostname] | Get-VMHostNetwork | Select Hostname,DnsAddress

 

This will set your host DNS settings (Primary / Secondary DNS servers)::

Get-VMHostNetwork -VMHost (Get-VMHost -Name [hostname]) | Set-VMHostNetwork -DnsAddress [Primary DNS],[Secondary DNS]

 

This will list the VMs connected to a specific port group:

Get-VM | where { ($_ | Get-NetworkAdapter | where {$_.networkname -match “portgroupname”})}

 

This will start the SSH service on all hosts in a cluster:

Get-Datacenter “[datacenter object name]” | Get-Cluster “[cluster name]” | Get-VMHost | Sort Name | Get-VMHostService | Where { $_.Key -eq “TSM-SSH”} | Start-VMHostService -confirm:$false

 

Stop SSH:

Get-Datacenter “[datacenter object name]” | Get-Cluster “[cluster name]” | Get-VMHost | Sort Name | Get-VMHostService | Where { $_.Key -eq “TSM-SSH”} | Stop-VMHostService -confirm:$false

Leave a Reply

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