Hello everyone,
I need assistance in creating two PowerCLI scripts which can export specific information to CSV files.
In the first report I would like to output the HBA information from the "Name", "Indentifier", "LUN", and "Capacity" fields
as seen in the screenshot directly below.
In the second report I would like to output the Storage information from the "Identification", "Device" and "Capacity" fields
as seen in the screenshot directly below.
I am a newbie to Powershell and PowerCLI and have seached the discussions and found some scripts which provide similiar information
but not quite exactly what I need. In my attempts to learn via "reverse engineering" all I accomplished was to hack the scripts and fail. =(
I am using the following PowerCLI version.
----------------
VMware vSphere PowerCLI 4.1 U1 build 332441
---------------
Snapin Versions
---------------
VMWare vSphere PowerCLI 4.1 U1 build 332441
Any help would be greatly appreciated.
Ok, try this for the 1st report
&{foreach($esx in Get-VMHost){ foreach($hba in (Get-VMHostHba -VMHost $esx -Type FibreChannel | where {$_.Status -eq "online"})){ Get-ScsiLun -Hba $hba | Select @{N="VMHost";E={$esx.Name}}, @{N="HBA";E={$hba.Device}}, @{N="DisplayName";E={$_.ExtensionData.DisplayName}}, @{N="Identifier";E={$_.CanonicalName}}, @{N="LUN";E={(Select-String ":L(?<lunID>\d+)$" -InputObject $_.RuntimeName).Matches[0].Groups['lunID'].Value}}, @{N="Capacity";E={"{0:f2}" -f ($_.CapacityMB/1KB)}} } } } | Export-Csv C:\hba-report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
First I would advise you to upgrade to PowerCLI 5.0.1 (unless you have a reason to stick with that older version).
The first report resembles somewhat what I my script in the Storage Adapters Output for vSphere (Devices+Paths) thread does.
The 2nd report is part of what I did in my LUN report – datastore, RDM and node visibility post.
Have a look at these and let me know if they help you achieve what you're after ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
Unfortunately the currently sanctioned/approved version of PowerCLI at my company is v4.1 which is why we cannot use v5.0.1 yet.
You are quite the legend on these boards and I have come across and attempted (unsuccessfully) to customize some of you scripts.
One from here..
http://communities.vmware.com/thread/321459
and the other from here...
http://communities.vmware.com/message/1766761
The other links you provided are somewhat similiar to what I am looking for but I need the output to be the information from the fields I specified as seen exactly within the VI Client GUI interface and the ability to run the scripts against individual ESX hosts within a cluster.
We have many LUN's which have been manually renamed over the years with different naming conventions and I need to be able to extract the information
to compare within Excel.
Also many LUN's have been provisioned with different SCSI ID's on each ESX host and I also need to compare them in order to clean up both of these messes.
Thanks!
Ok, try this for the 1st report
&{foreach($esx in Get-VMHost){ foreach($hba in (Get-VMHostHba -VMHost $esx -Type FibreChannel | where {$_.Status -eq "online"})){ Get-ScsiLun -Hba $hba | Select @{N="VMHost";E={$esx.Name}}, @{N="HBA";E={$hba.Device}}, @{N="DisplayName";E={$_.ExtensionData.DisplayName}}, @{N="Identifier";E={$_.CanonicalName}}, @{N="LUN";E={(Select-String ":L(?<lunID>\d+)$" -InputObject $_.RuntimeName).Matches[0].Groups['lunID'].Value}}, @{N="Capacity";E={"{0:f2}" -f ($_.CapacityMB/1KB)}} } } } | Export-Csv C:\hba-report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And this should produce the 2nd report
&{foreach($esx in Get-VMHost){ $lunTab = @{} Get-ScsiLun -VMHost $esx | %{ $lunTab.Add($_.CanonicalName,$_.ExtensionData.DisplayName) } Get-Datastore -VMHost $esx | where {$_.Type -eq "VMFS"} | Select @{N="VMHost";E={$esx.Name}}, @{N="Identification";E={$_.Name}}, @{N="Device";E={$lunTab[$_.ExtensionData.Info.Vmfs.Extent[0].DiskName]}}, @{N="Capacity";E={"{0:f2}" -f ($_.CapacityMB/1KB)}} } } | Export-Csv C:\ds-report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Excellent! That was exactly what I needed.
Perfect!!
Both scripts which you provided give me the exact information I need in order to perform cleanups on all of our disparate clusters.
You are the man!
Have a great weekend!
LucD,
Any change in script if we use to execute in Powercli ver 5.0.?
Thanks
vmguy
No, the scripts should run in PowerCLI 5.x as well
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks !!
vmguy