How to use hash table with Powercli

Hash table is a data structure where we can store our data.Comparing to the data arrays in powercli/powershell , the main difference is with hash table we can easily handle multiple type of data such as Integer,String,etc..

Some times we need to generate reports using some of the PowerShell commands(export-csv,out-file,add-content).With below example my requirement is to generate vm report which include VMname,Datastore name,Network port group and vmawre tools status.But to gather all the information we have to use multiple get commands and then its difficult to consolidate this data.Hash table was helped me on this.I can gather values from multiple commands and assign to hash table.I have highlghted hash table related commands in my script.

import-module vmware.vimautomation.ha

connect-viserver vcsa.corp.local


foreach ($vm in $vms)

     $dstore=get-vm $|get-datastore
     $nicport=(get-vm $
     $vmtools=(get-vm $


$result+=new-object psobject -property $properties
$result|select name,datastore,network,vmwaretools|export-csv d:\mycsv.csv -append -notypeinformation


Leave a Reply

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

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: