VMware Cloud Community
jessem
Enthusiast
Enthusiast
Jump to solution

Command or script needed to get Datastore, NAA identifier and multipath

The following script/command gets me the multipath policy on a csv file, however, I need it to also identify the 'Datastore' name with the naa number.

get-cluster 'windows 01' | get-vmhost | get-scsilun -luntype disk | Export-csv c:\lun_multipath.csv

any help would be appreciated.

Reply
0 Kudos
29 Replies
jessem
Enthusiast
Enthusiast
Jump to solution

I can't find that line in your script?  Where is this?

$entry.datastorename= $datastore | Where-Object { $_.extensiondata.info.vmfs.extent.diskname -like $disk.canonicalname}|select -expand name


Here is the script I have, unless I have the wrong one?

-------------------------------

param($clusName,$csvName=("C:\Temp\" + $clusName + "-LUN.csv"))

$rndNum = Get-Random -Maximum 99999

$LunInfoDef = @"

  public string ClusterName;

  public string CanonicalName;

  public string UsedBy;

  public string SizeMB;

"@

$LunInfoDef = "public struct LunInfo" + $rndNum + "{`n" + $LunInfoDef

$esxServers = Get-Cluster $clusName | Get-VMHost | Sort-Object -Property Name

$esxServers | %{

  $LunInfoDef += ("`n`tpublic string " + ($_.Name.Split(".")[0]) + ";")

}

$LunInfoDef += "`n}"

Add-Type -Language CsharpVersion3 -TypeDefinition $LunInfoDef

$scsiTab = @{}

$esxServers | %{

  $esxImpl = $_

# Get SCSI LUNs

  $esxImpl | Get-ScsiLun | where {$_.LunType -eq "Disk"} | %{

  $key = $esxImpl.Name.Split(".")[0] + "-" + $_.CanonicalName.Split(".")[1]

  if(!$scsiTab.ContainsKey($key)){

  $scsiTab[$key] = $_.CanonicalName,"",$_.CapacityMB

  }

  }

# Get the VMFS datastores

  $esxImpl | Get-Datastore | where {$_.Type -eq "VMFS"} | Get-View | %{

  $dsName = $_.Name

  $_.Info.Vmfs.Extent | %{

  $key = $esxImpl.Name.Split(".")[0] + "-" + $_.DiskName.Split(".")[1]

  $scsiTab[$key] = $scsiTab[$key][0], $dsName, $scsiTab[$key][2]

  }

  }

}

# Get the RDM disks

Get-Cluster $clusName | Get-VM | Get-View | %{

  $vm = $_

  $vm.Config.Hardware.Device | where {$_.gettype().Name -eq "VirtualDisk"} | %{

  if("physicalMode","virtualmode" -contains $_.Backing.CompatibilityMode){

  $disk = $_.Backing.LunUuid.Substring(10,32)

  $key = (Get-View $vm.Runtime.Host).Name.Split(".")[0] + "-" + $disk

  $scsiTab[$key][1] = $vm.Name + "/" + $_.DeviceInfo.Label

  }

  }

}

$scsiTab.GetEnumerator() | Group-Object -Property {$_.Key.Split("-")[1]} | %{

  $lun = New-Object ("LunInfo" + $rndNum)

  $lun.ClusterName = $clusName

  $_.Group | %{

  $esxName = $_.Key.Split("-")[0]

  $lun.$esxName = "ok"

  if(!$lun.CanonicalName){$lun.CanonicalName = $_.Value[0]}

  if(!$lun.UsedBy){$lun.UsedBy = $_.Value[1]}

  if(!$lun.SizeMB){$lun.SizeMB = $_.Value[2]}

  }

  $lun

} | Export-Csv $csvName -NoTypeInformation -UseCulture

Invoke-Item $csvName


Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Not in my script, in the one that Conrad gave earlier


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

Reply
0 Kudos
jessem
Enthusiast
Enthusiast
Jump to solution

great, that worked!  one last request, pardon my ignorance.  Any way to get the hostname added to the csv report?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

$datastore = get-datastore

$disks = get-cluster 'windows 01' | get-vmhost | get-scsilun -luntype disk
$entry = @()
$output = @()
ForEach ($disk in $disks){
 
$entry = "" | Select DataStorename, HostName, Canonicalname, Multipathing
 
$entry.datastorename= $datastore | Where-Object {($_.extensiondata.info.vmfs.extent | %{$_.diskname}) -contains $disk.canonicalname}|select -expand name
 
$entry.HostName = $disk.VMHost.Name
 
$entry.canonicalname=$disk.canonicalname
 
$entry.multipathing=$disk.multipathpolicy
 
$output += $entry
}
$output | Export-csv c:\lun_multipath.csv


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

Reply
0 Kudos
jessem
Enthusiast
Enthusiast
Jump to solution

Thanks for you and Conrad's help!

Reply
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

Im trying to post a reply on your site but it doesnt seem to be working so I'll send my response here...

The script works great for me other than the fact that the csv that gets created doesnt have a value under VMName which would be cool to have. I also get an error referring to the CanonicalName, but that data does show in the csv file. I get the error numerous times and it looks like it per host, heres the error.

Get-ScsiLun : Cannot validate argument on parameter 'CanonicalName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

At H:\VM Scripts\storage_details.ps1:76 char:59

+ $RuntimeName = Get-ScsiLun -vmhost $vmHost -CanonicalName $naaid | Select -Expan ...

+                                                           ~~~~~~

    + CategoryInfo          : InvalidData: (:) [Get-ScsiLun], ParameterBindingValidationException

    + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.GetScsiLun

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yeah, comments on my blog need to be approved before you see them, otherwise I would have too much spam comments.

Could it be that you have some datastores that are not VMFS datastores but NFS or iSCSI ?


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

Reply
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

That would make sense actually....

What about getting the VMName to populate? Its just showing as blank fields

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you referring to my LUN report – datastore, RDM and node visibility post ?

In there the VMname is shown in the UsedBy column if the LUN is used as RDM


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

Reply
0 Kudos
justinsmith
Enthusiast
Enthusiast
Jump to solution

Yes Im referring to that post.

I put 2 and 2 together. We have so many blanks in either the VMName and or the Datastore name along with 1100+ rows, it made it kind of a pain to find what I needed. But Filter > sort in Excel is your friend.

Thanks again

Reply
0 Kudos