Hello, I am trying to create a script that returns the info from the Configuration/Storage/Datastore/Datastore Details . The thing I want the script to do is list my ESX:s, list datastore names, list mpathpolicy and the Paths section of the datastore Details in the VI client.
Is there possible to get this in a script? Or if anyone knows how I can get info from the Paths info in the Datastore Details view in VI client
Thanks in advanced
That's possible if you use the SDK properties.
The following script lists the hostname, DS name, path policy and the number of paths.
If you need other information from the Details page in the report let me know.
$report = @() Get-VMHost | Get-View | %{ $esx = $_ $esx.Datastore | %{Get-View $_} | where {$_.SUmmary.Type -eq "VMFS"} | %{ $ds = $_ $ds.Info.Vmfs.Extent | %{ $ext = $_ $extKey = ($esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName -eq $ext.DiskName}).Key $lun = $esx.Config.StorageDevice.MultipathInfo.Lun | where {$_.Lun -eq $extKey} $row = "" | Select ESXname, DSname, "Path Selection","Paths Total" $row.ESXname = $esx.Name $row.DSname = $ds.Name $row."Path Selection" = &{ switch($lun.Policy.Policy){ "VMW_PSP_FIXED"{"Fixed"} "VMW_PSP_RR"{"Round Robin"} "VMW_PSP_MRU"{"Most Recently Used"} } } $row."Paths Total" = $lun.Path.Count $report += $row } } } $report
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's possible if you use the SDK properties.
The following script lists the hostname, DS name, path policy and the number of paths.
If you need other information from the Details page in the report let me know.
$report = @() Get-VMHost | Get-View | %{ $esx = $_ $esx.Datastore | %{Get-View $_} | where {$_.SUmmary.Type -eq "VMFS"} | %{ $ds = $_ $ds.Info.Vmfs.Extent | %{ $ext = $_ $extKey = ($esx.Config.StorageDevice.ScsiLun | where {$_.CanonicalName -eq $ext.DiskName}).Key $lun = $esx.Config.StorageDevice.MultipathInfo.Lun | where {$_.Lun -eq $extKey} $row = "" | Select ESXname, DSname, "Path Selection","Paths Total" $row.ESXname = $esx.Name $row.DSname = $ds.Name $row."Path Selection" = &{ switch($lun.Policy.Policy){ "VMW_PSP_FIXED"{"Fixed"} "VMW_PSP_RR"{"Round Robin"} "VMW_PSP_MRU"{"Most Recently Used"} } } $row."Paths Total" = $lun.Path.Count $report += $row } } } $report
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
THANK YOU, I am very glad for the respons you gave me.
Another question about the script you gave me is, is there a way to split the outcome of it all like foreach-object ($esx. jadajada) so that the result lists the info for each ESX.
ESXname DataStoreName MultiPathPolicy numberofPats
ESX1 Datastore08 Fixed 4
ESX1 Datastore09 Fixed 4
ESX1 Datastore10 Fixed 4
ESXname DataStoreName MultiPathPolicy numberofPats
ESX2 Datastore01 Fixed 4
ESX2 Datastore01 Fixed 4
ESX2 Datastore01 Fixed 4
Try replacing the last line with this line
... $report | ft -GroupBy ESXname
That will give you output like this
ESXname: ESX1 ESXname DataStoreName MultiPathPolicy numberofPats ESX1 Datastore08 Fixed 4 ESX1 Datastore09 Fixed 4 ESX1 Datastore10 Fixed 4 ESXnam: ESX2 ESXname DataStoreName MultiPathPolicy numberofPats ESX2 Datastore01 Fixed 4 ESX2 Datastore01 Fixed 4 ESX2 Datastore01 Fixed 4
Not exactly what you wanted but perhaps close enough ?
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello again, yes that is exactly the thing I was looking for. But here comes the next problem, when you use Format-Table you cant pipe the output to convertto-csv or convertto-html . As they explain in this blog http://blogs.msdn.com/b/powershell/archive/2007/03/07/why-can-t-i-pipe-format-table-to-export-csv-an...
The problem is that I use the convertto-html in my script.
Anyway, I am really thankful for your help. Next beer on me .
thanks again.
I'm afraid the ConvertTo-Html will not allow you to do that easily.
You can of course roll your own.
Give the attached script a go, it produces a HTML file with layout you envisaged.
Note that it is a plain HTML page, I'm no web designer I'm afraid
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This script when run is asking a process name to enter. What is that?
Ok, this is the script you are trying to run.
From where do you try to run the script ? From the PowerCLI prompt ? From the ISE ?
Which PowerCLI version are you using ?
Do a
Get-PowerCLIVersion
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Power CLI version is ----------------
VMware vSphere PowerCLI 4.1 build 264274 .
Anyways, it worked now. I messed up with the brackets .