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 {
 $objreport=@()

 get-vmhost | % {

 $intvmcommitmemmb=$null
 $intvmcommitcpu=$null

 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 
 }#endhost

 return $objreport
}#endfunction

get-commitment

A function to report all machines with snapshots:

function get-snapshots {
 $i=$null 
 $result=@()
 $objAllservers = get-vm
 foreach ($server in $objAllservers){
 $i++
 $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
 

Related Posts

New Module: Creating an RDP file password with Pow... Here's something that is surprisingly tricky to automate in this day and age. Creating a password and storing it in an RDP file. I'm not here to debat...
Dealing with multi numbered versions in powershell... So here's a quick little blog about something i discovered in powershell while googling today. Lots of vendors like to use version numbers includin...
Accurately checking the Citrix PVS “cache in... Citrix Provisioning services "Cache in RAM, overflow to disk", even with it's challenges is something I've always felt was a great idea, hell, I fores...

Leave a Reply