Home > PowerClI, PowerShell Scripting > VMWare Powercli one liners & simple functions:

VMWare Powercli one liners & simple functions:

I attended the VCP 410 training course last week (install, configure & manage). I found this training very interesting but the real thief of my attention was just how good the vmware vSphere Powercli modules and cmdlets were. Below are a few one-liners I wrote as the week went on out of boredom and curiosity.

Hopefully I soaked in enough of the course through partial listening while reading the powercli help references to pass my exam today!

Retrieve and Apply DRS recommendations:

get-drsrecommendation | Apply-DrsRecommendation

Find all vm’s with e1000 network cards, for upgrade to vmxnet:

get-vm | Get-NetworkAdapter | where {$_.type -match “e1000”} | select-object parent,networkname,name,type

power off all vm’s with “test” in their names:

get-vm test* | stop-vm -confirm:$false

Move all vm’s with “test” in their names:

get-vm | where {$_.name -like “*test”} | move-vm -destination destinationhostname

Remove all vm’s with “test” in their name:

get-vm test* | remove-vm -confirm:$false

retrieve a list of vm’s with thinly provisioned disks:

get-vm | select HardDisks -expandproperty HardDisks | where {$_.storageformat -match “Thin”} | select-object parent,name,capacitykb,filename

A function to report on physical resources vs virtual commitment:

function get-commitment {

 get-vmhost | % {


 get-vm -location $_ | % {
 $intvmcommitcpu += $_.numcpu
 $intvmcommitmemmb += $_.MemoryMB
 }#end vm

 $objOutput = New-Object PSObject -Property @{
 VMHost = $_.name
 VMMaxCpu = $_.NumCpu
 VMCommitCPU = $intvmcommitcpu
 VMMaxMem = $_.MemoryTotalMB
 VMCommitMem = $intvmcommitmemmb
 }#end object
 $objreport += $objoutput 

 return $objreport


A function to report all machines with snapshots:

function get-snapshots {
 $objAllservers = get-vm
 foreach ($server in $objAllservers){
 $intsize = $intsize + $objallservers.length
 Write-Progress -activity "Gathering snapshot report ($server)" -status "Percent complete: " -PercentComplete (($i / $objAllservers.length) * 100)
 $result += get-snapshot $server}

 return $result

get-snapshots | select-object name,created,sizemb,iscurrent,vm,vmid,Id,Uid

pass the vcp exam: (work in progress)

get-coursenotes |
select-object salespitch,minimums,maximums,configurationlimitations |
commit-tobrain | out-exampaper
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

<span>%d</span> bloggers like this: