Link to home
Start Free TrialLog in
Avatar of compdigit44
compdigit44

asked on

Powercli + List all VM's Per SCSILUN

I need to get a list of all VM that are on each storage type we have and using the following:

Get-vmhost | get-scsilun -canonicalName "eui.000315462fc*"

I am finding that Get-SCSILun is not letting me easily take the CanonicalName and match this to the datastore name and corresponding VM's,

Thoughts.
Avatar of Mike O
Mike O
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,
I really like using PowerShell whenever I can and for whatever it's best for, but sometimes I find that other tools are just better (Keep it Simple Stupid [Kiss], as they say). For this I'd use RV Tools
It just connects to your vCenter or ESXi host and extracts loads of information. You can save it into Excel or CSV and then perform all sorts of data manipulation on it - depending on your excel skills :-)
The various tabs will tell you ever datastore and its storage type, also the location of each VMs VMX file, and all of the VMDKs. That should cover everything you need.

If it's a one off, that should cover your needs.

If you need to do this on a regular basis, you might want to look into the options it has for scripting.
Avatar of compdigit44
compdigit44

ASKER

I do use RvTools and will see if I can list all VM by LUN ID type. I am surprised I cannot else get this info via poweshell
Avatar of Luciano Patrão
Hi,

Even this week I needed to create a powercli script to change some settings in some of iSCSI LUNs and needed to use that commands.

This is how you can list and use  -canonicalName

Get-VMHost | Get-ScsiLun -LunType disk | Where {$_.CanonicalName -like "naa.6006" -or $_.CanonicalName -like "naa.60a"}

Jail
Hi again,

Just be aware that VMs can only be listed per Datastore, not by LUNs.

If I want to list all VMs in a particular Datastore that needs to be an iSCSI with particularly CanonicalName, I will do something like this will give you VMs in that Datastore:

Get-VMhost $hostname | Get-Datastore | where {get-VMHost $hostname | Get-ScsiLun -LunType disk |  Where {$_.CanonicalName -like "eui.000315462fc*"}} | get-vm
Thank you very much for the feedback. I tried to use  the syntax you listed but it kept erroring out and used the following below..

Get-VMhost  | Get-Datastore | where {get-VMHost  | Get-ScsiLun |  Where {$_.CanonicalName -like "eui.000315462fc*"}} | get-vm | select-object name | out-file C;\IBM.txt

The script runs but I am finding that it is not providing the correct information . For example I know the script will taka while to run since I have 110 hosts but I stop after looking at the outfile and notice VMs were listed that where not on the LUN's from the storage vendoer listed
Hi

Because you not pointing to any host, you are reading all.

So you need to do a foreach and point that read to the host to read one each time.

If use the command I have added and use a host name, you will see the real VMs.
I totally understand but I need to have this scan my whole vcenter environment.. Is below the correct syntax

Get-VMhost  | Get-Datastore | for-each{{get-VMHost  | Get-ScsiLun |  Where {$_.CanonicalName -like "eui.000315462fc*"}} | get-vm }| select-object name | out-file C;\IBM.txt
I know, this why I said you need to create a Foreach to do that.

You need a foreach for the hosts and also a foreach for datastore so that the script will also read all datastores.
I am not strong in powershell yet but is the syntax I posted earlier correct?
When I used the syntax listed  I get the error get-vm : The input object cannot be bound to any parameters....

Get-VMhost  | Get-Datastore | foreach{{get-VMHost  | Get-ScsiLun |  Where {$_.CanonicalName -like "eui.0017380031e8*"}} | get-vm }| select-object name | out-file C:\IBM.txt
ASKER CERTIFIED SOLUTION
Avatar of Luciano Patrão
Luciano Patrão
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This worked perfectly... I need to read up on ForEach loops more.

Thanks Again!!!!!
I recommend RvTools as well. It is easy and simple to use. AND FREE!
I did try RvTools but it did not do quite what I was looking for.