VMware Cloud Community
system_noida
Enthusiast
Enthusiast
Jump to solution

Fetch Extent Details from Multiple Datastore

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.

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

0 Kudos
11 Replies
LucD
Leadership
Leadership
Jump to solution

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

 

yes , thats correct, but I need to input he CSV file with selected datastore only. Pls could you help with that

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

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.

system_noida_0-1630500651828.png

 

0 Kudos
LucD
Leadership
Leadership
Jump to solution

My bad, typo, that should have been Filter.
I corrected the code above.


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

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Hi Luc,

 

The script is working perfectly. Just one more query, 🙂 Can I export the data in a file pls .

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Sure, change the last line

$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture


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

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Thanks you so much LucD.... you are super 🙂 . your script solved my big problem.

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

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.

Tags (1)
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
system_noida
Enthusiast
Enthusiast
Jump to solution

Thanks so much mate!

Tags (1)
0 Kudos