Category Archives: powershell

PS: How to get ESXi multipath storage with Powerpath

If your vSphere’s ESXi hosts are connected to storage via EMC’s powerpath, the convention methods of querying path info will not work. Basically, you will get zero results.

For example when you query the lun via MultipathInfo you may only see iSCSI luns listed (if you have them running), but not your datastores. Read the rest of this entry »

Leave a comment

Posted by on August 21, 2018 in powershell, vmware


PS: Getting a virtual machine’s properties in vRA

Getting the properties of a VM provisioned in vRA is not straight forward, you need to get those information from the IaaS Web server instead of from vRA

This site shows you how you can get to it.

I am not sure which version the author has, but in version 7.2 the properties are not so straight forward and they strangely don’t expand when exported to a JSON file. However let’s first deal with the NTLM authentication on IaaS Web via a Invoke-RestMethod call. Its actually very straight forward, but hard to find; simply speaking, you use get-credential to capture the windows credentials and input it with -credential parameter. Read the rest of this entry »

Leave a comment

Posted by on August 2, 2018 in powershell, vmware


Tags: ,

PS: Adding nodes to JSON object

Whilst working on vRA REST API to provision new virtual machines, one of task was to get the template for that catalog item and fill in required values.

One of the values common to most templates is the datacenter_location value. By default it will be null. That is not a big deal if you don’t care which datacenter your VM is being provisioned to, but what if you want to specify a location?

"_cluster": 1,
"_hasChildren": false,
"cpu": 1,
"datacenter_location":  null,

In this case the values should be as such

 "_cluster": 1,
"_hasChildren": false,
"cpu": 1,
"datacenter_location": {
               "classId": "Infrastructure.Compute.DataCenterLocations",
               "id": "DC1"

This is how you can add the values into the JSON object (I am assuming that you already gotten the bearer token in the $vratoken variable) Read the rest of this entry »

Leave a comment

Posted by on August 2, 2018 in powershell, vmware


Tags: , ,

Daily health check script for VMAX storage

One of the challenge for our cloud team is daily checks. Not coming from a storage background, we did our daily checks by logging on to the storage web gui daily. Interestingly, there is almost no daily check scripts to be found. However, I found a reference in the EMC forum a list of commands to run for a generic health checks.

symcfg list -sid $vmax_sid -env_data -v
symcfg list -sid $vmax_sid -dir ALL
symdev -sid $vmax_sid list -v
symevent -sid $vmax_sid list -error -fatal
symdisk list -sid $vmax_sid -failed

The next task now is to put these into a health check script and figure out the output messages to check for errors.  In general, you just need to check for devices that reports degraded, failed, error or one of standard errors. However for the symdisk command, the execution is different:

symdisk list -sid $vmax_sid -failed

Read the rest of this entry »

Leave a comment

Posted by on July 6, 2018 in powershell


Tags: , , , , , ,

PS: Continuous ping of a list of VMs

Generally, continuous pings are very easy, we can even do it from Windows command prompt. However, recently, I need a more generic script used to ping a list of VMs and color code status and it expanded from there to include other stuff I want to with the script.

Note that the script is used to ping a set of VMs in my environment that is why the input CSV has VMHost as a column. You can always change this to suit your needs.

Param (
  [ValidateScript({If(Test-Path $_){$true}<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>else{Throw "Invalid file given: $_"}})]

$ListOfVMs = import-csv $inputfile
if ($first -eq 0) {$first = $ListOfVMs.count}
$ListofVMs = $ListofVMs | select -first $first -skip $skip
do {

  Write-Host "Checking Status ... "
  Write-Host " "

  foreach ($VM in $ListOfVMs) {
    $VMHost = $VM.VMHost
    $VMName = $VM.Name
    $IPAddress = $VM.IPAddress

    if ($v) {
       Write-Host "Pinging... $VMHost : $VMName with $IPAddress" -ForegroundColor yellow
       Test-Connection $IPAddress -EA SilentlyContinue
    else {
       if (Test-Connection $IPAddress -count $count -quiet -EA SilentlyContinue) {
         Write-Host "$VMHost : $VMName with $IPAddress is UP" -foregroundcolor Green
       else {
         Write-Host "$VMHost : $VMName with $IPAddress is DOWN" -foregroundcolor Red


  Write-Host " "

  if ([console]::KeyAvailable) {
    $x = [System.Console]::ReadKey()
    if ($x.key -match "Q") {
	  Write-Host "Keystroke Q detected, quiting loop"

  if ($loop -and !$Endloop) {
    Write-Host "Continuous ping enabled, press Q to end loop ... "
    Write-Host " "
	sleep 1

} while($loop -and !$Endloop)

Write-Host " "

Leave a comment

Posted by on April 20, 2018 in powershell



PS: One-line create a custom object list

The one-liner challenge for me today:

  • Get a list of random VMs from each ESXi host in a cluster
  • Send the host name, vm name and IP address to a CSV file

Normally, this is straight forward, but because we only need grab 2 VMs from each host, it is not possible to just  pipe the VM objects into a CSV file since the loop breaks between each host. The solution is to store all records into a array of custom objects and then pipe that into a CSV file at the end.

$ListOfVMs = @() ;
get-cluster | ? { $ -match "cluster1" } |
get-vmhost | % { $_ | get-vm | ? { $ -match "dev" } |
select -first 2 |
% { $t = @{} |
    select VMhost,Name,IPAddress ;
    $t.VMHost = $_.VMHost;
    $t.Name = $_.Name ;
    $t.IPAddress = $_.guest.IPAddress[0] ;
    $ListOfVMs += $t }
} ; $ListOfVMs | export-csv .\mylist.csv -NoTypeInformation


Leave a comment

Posted by on April 18, 2018 in powershell


Tags: , , ,

Formatting XML output XML file

Below is a format-xml script which a lot of helpful scripters posted on the net. You can make a REST API call and use it to indent the output.

For example, you can indent the XML from an NSX REST API call.

#assumming all other pre-requisites for this call is done
$head = #this contains the authorisations string
$Request = "https://nsxmrg/api/3.0/edges"
[xml]$r = Invoke-WebRequest -Uri $Request -Headers $head -ContentType "application/xml" -ErrorAction:Stop


Read the rest of this entry »

Leave a comment

Posted by on April 17, 2018 in powershell


Tags: , ,