VMware Cloud Community
kondratyevmn
Contributor
Contributor

Script -> show host, LUN(datastore), path selection based on list of VM.

Hello PowerCLI gurus!

Could you please help me with the following task:

Let's imagine, I have a list of VMs. I need to have a report for each of these VMs, which will show me on which host these VM's currently working, on which datastore / LUN files of VMs are located and what type of path selection has chosen. It would be great a possibility to withdraw these data to CSV file.

Thank you in advance.

4 Replies
LucD
Leadership
Leadership

You could try something like this.

Note the script assumes VMFS datastores.

$vmNames = Get-Content vmnames.txt

Get-VM -Name $vmNames -PipelineVariable vm | %{

    Get-View  -Id $_.DatastoreIdList |

    Select @{N='VM';E={$vm.Name}},

        @{N='Datastore';E={$_.Name}},

        @{N='LUN';E={$_.Info.Vmfs.Extent[0].DiskName}},

        @{N='PathPolicy';E={Get-ScsiLun -CanonicalName $_.Info.Vmfs.Extent[0].DiskName -VmHost $vm.VMHost | select -ExpandProperty MultiPathPolicy}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
kondratyevmn
Contributor
Contributor

Hello LucD!

First of all, thank you for your reply and help. The output contain information about the VM, Datastore, LUN. However, the PathPolicy is fully empty. How do you think, where is the problem should be?

P.S. VMFS on all datastores in our infrastructure.

Reply
0 Kudos
LucD
Leadership
Leadership

Are you by any chance using EMC PowerPath?

Does this display the policy?

$vmNames = Get-Content vmnames.txt

Get-VM -Name $vmNames -PipelineVariable vm | %{

    Get-View  -Id $_.DatastoreIdList |

    Select @{N='VM';E={$vm.Name}},

        @{N='Datastore';E={$_.Name}},

        @{N='LUN';E={$_.Info.Vmfs.Extent[0].DiskName}},

        @{N='PathPolicy';E={(Get-EsxCli -VMHost $vm.VMHost).storage.nmp.device.list($_.Info.Vmfs.Extent[0].DiskName) | Select -ExpandProperty PathSelectionPolicy}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

kondratyevmn
Contributor
Contributor

Mmm.. I am not sure, I guess not.

Yeah! This is what working for me. Thank you very much! Smiley Happy

Reply
0 Kudos