/PowerCLI: VMware List VM’s per Datastore vs CanonicalName.

PowerCLI: VMware List VM’s per Datastore vs CanonicalName.

This week I need to create a script to list all VMs. This particular script display all VMs that are inside in some particularly iSCSI LUNs. Since VMware environment could have iSCSI, NFS and also Local Disks, so we need to search by CanonicalName. In this case iSCSI LUN CanonicalName.

Some examples of CanonicalName that we can search with Get-ScsiLun:

mpx.vmhba1:C0:T0:L0 – Local Storage
naa.600508b1001cd496d9b6de3cd17** – Local Disks
eui.0824c2ed87fe91f6 or eui.7d374ff1ab9a3558 – iSCSU LUNs

Note: If you want to exclude the Local Disks and/or Local Storage from the search, just add  -and $_.IsLocal -like “False”  in the Get-ScsiLun.

So by searching the CanonicalName, we can search and List all VMs inside. We can use CanonicalName for iSCSI, Local Disks, and Local Storage(system). In this case, we are only using for iSCSI LUNs.

This is the script:

The initial part of this script (the New-VIProperty parameter) was based on a script that we found in www.vsysad.com.

Note: Again many thanks to my colleague Vladimir Sokol for is scripting qualities for the help, improvement and also taking the script to a higher next level.

Hope this script can help and be useful.

Note: Share this article, if you think is worth sharing.

©2017 ProVirtualzone. All Rights Reserved
By | 2018-03-12T01:46:58+01:00 February 26th, 2017|VMware Posts|0 Comments

About the Author:

I have over 20 years of experience in the IT industry. I have been working with Virtualization for more than 15 years (mainly VMware). I recently obtained certifications, including VCP DCV 2022, VCAP DCV Design 2023, and VCP Cloud 2023. Additionally, I have VCP6.5-DCV, VMware vSAN Specialist, vExpert vSAN, vExpert NSX, vExpert Cloud Provider for the last two years, and vExpert for the last 7 years and a old MCP. My specialties are Virtualization, Storage, and Virtual Backup. I am a Solutions Architect in the area VMware, Cloud and Backup / Storage. I am employed by ITQ, a VMware partner as a Senior Consultant. I am also a blogger and owner of the blog ProVirtualzone.com and recently book author.

Leave A Comment