Category Archives: PowerClI

Viewing VMware Unified Access Gateway statistics with REST


<Tap Tap> Is this thing still on? Good!

The VMware Unified Access Gateway really is a wonderful device. With a quick deployment of an OVF you’re up and running with free remote access to your VMware Horizon environment. The device is so simple in fact, that it’s often a case of set and forget, it does the hard work freeing you up to do more important things.

A request came in from a customer last year to be able to view more about what this little magic appliance is doing, how healthy it is and how many  users it is currently servicing.

For VMware vRealize Operations for Horizon customers, this data is all available directly in the VROPS portal, but what if you don’t have VMware vRealize Operations for Horizon? or want to query this in an automated fashion?

Continue reading

Unique portgroup fiddling with #Powercli.

As my peers seem to like to flout convention, particularly naming conventions. I was left with a strange automation challenge this week.

with a new service coming online in my company, I had 12 vlan portgroups to add to over 30 ESXi machines. Simple you say, just pipe your hosts into a new virtualswitch query then into a new virtual port group command.

Did i mention the virtual switch has a different name per host? Its vswitch0 on some, vswitch1 on others, and even vswitch2 on one.Arse.

after a few hours of various queries, below is the little scripty I was left with. I did consider putting this into a function, but I didnt know where to begin when it came to a name…

add-PortGroupInSwitchWhereOtherPortGroupExists? … bleh.

Below the variables are pretty self explanatory and it works flawlessly. Remember to install the powercli commands, import the module and connect to the vi server first!


foreach ($portgroup in get-virtualportgroup | where {$ -eq $findportgroupname}){
 get-vmhost -id $portgroup.vmhostid |
  get-virtualswitch -name $portgroup.virtualswitchname |
   new-virtualportgroup -name $NewPortGroupName -Vlanid $NewPortGroupVlanId

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 {$ -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 = $
 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