Hi All,
I need to pull out the details of Extents from some multiple datastore along with NAA ID and Datastore name, so I am looking some kind of powercli script which can help with me. Please can anyone help with me that.
Assuming there is a column called Name in the CSV, you could do something like this
$report = @()
$dsNames = (Import-Csv -Path .\datastorenames.csv -UseCulture).Name -join '|'
Get-View -ViewType Datastore -Filter @{Name=$dsNames} -PipelineVariable ds |
ForEach-Object -Process {
$esx = Get-View -Id $ds.Host[0].Key
$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, Extent, Partition, "Path Selection","Paths Total"
$row.ESXname = $esx.Name
$row.DSname = $ds.Name
$row.Extent = $ext.DiskName
$row.Partition = $ext.Partition
$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.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean something like this?
Solved: Re: Possible to query Extent details on datastore ... - VMware Technology Network VMTN
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
yes , thats correct, but I need to input he CSV file with selected datastore only. Pls could you help with that
Assuming there is a column called Name in the CSV, you could do something like this
$report = @()
$dsNames = (Import-Csv -Path .\datastorenames.csv -UseCulture).Name -join '|'
Get-View -ViewType Datastore -Filter @{Name=$dsNames} -PipelineVariable ds |
ForEach-Object -Process {
$esx = Get-View -Id $ds.Host[0].Key
$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, Extent, Partition, "Path Selection","Paths Total"
$row.ESXname = $esx.Name
$row.DSname = $ds.Name
$row.Extent = $ext.DiskName
$row.Partition = $ext.Partition
$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.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, I put the content in a ps1 file and created a csv file . when I am trying to run it I am getting below error.
My bad, typo, that should have been Filter.
I corrected the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
The script is working perfectly. Just one more query, 🙂 Can I export the data in a file pls .
Sure, change the last line
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks you so much LucD.... you are super 🙂 . your script solved my big problem.
Hi Luc,
Is there any chance to get the LUN ID too for these extent with the help of below script pls. sorry I am just looking on google but unable to get in right direction.
You could do something like this
$report = @()
$dsNames = (Import-Csv -Path .\datastorenames.csv -UseCulture).Name -join '|'
Get-View -ViewType Datastore -Filter @{Name = $dsNames } -PipelineVariable ds |
ForEach-Object -Process {
$esx = Get-View -Id $ds.Host[0].Key
$ds.Info.Vmfs.Extent | ForEach-Object {
$ext = $_
$extKey = ($esx.Config.StorageDevice.ScsiLun | Where-Object { $_.CanonicalName -eq $ext.DiskName }).Key
$lun = $esx.Config.StorageDevice.MultipathInfo.Lun | Where-Object { $_.Lun -eq $extKey }
$row = "" | Select-Object ESXname, DSname, Extent, Partition, "Path Selection", LunId,"Paths Total"
$row.ESXname = $esx.Name
$row.DSname = $ds.Name
$row.Extent = $ext.DiskName
$row.Partition = $ext.Partition
$row."Path Selection" = & {
switch ($lun.Policy.Policy) {
"VMW_PSP_FIXED" { "Fixed" }
"VMW_PSP_RR" { "Round Robin" }
"VMW_PSP_MRU" { "Most Recently Used" }
}
}
$row.LunID = $lun.Path.Name.Split('L')[1]
$row."Paths Total" = $lun.Path.Count
$report += $row
}
}
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks so much mate!