1 2 Previous Next 29 Replies Latest reply on May 20, 2015 3:54 PM by justinsmith

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

    jessem Enthusiast

      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.

        • 1. Re: Command or script needed to get Datastore, NAA identifier and multipath
          LucD Guru
          vExpertCommunity WarriorsUser Moderators
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Command or script needed to get Datastore, NAA identifier and multipath
            CRad14 Hot Shot

            I just quickly threw this together....it's not pretty but I think it should work for you

             

            $datastore=get-datastore

             

            $disks=get-cluster 'windows 01' | get-vmhost | get-scsilun -luntype disk

            $entry=@()

            $output=@()

            ForEach ($disk in $disks)


            {

            $entry="" | Select DataStorename, Canonicalname, Multipathing

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

            $entry.canonicalname=$disk.canonicalname

            $entry.multipathing=$disk.multipathpolicy

            $output+=$entry

            }

             

            $output | Export-csv c:\lun_multipath.csv

            • 3. Re: Command or script needed to get Datastore, NAA identifier and multipath
              jessem Enthusiast

              I tried this but the datastore name column does not have anything in it?...

              • 4. Re: Command or script needed to get Datastore, NAA identifier and multipath
                LucD Guru
                vExpertUser ModeratorsCommunity Warriors

                Did you try the script in the post I linked to ?

                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                • 5. Re: Command or script needed to get Datastore, NAA identifier and multipath
                  jessem Enthusiast

                  I'm trying to read thru it but it's a little confusing for me

                  • 6. Re: Command or script needed to get Datastore, NAA identifier and multipath
                    LucD Guru
                    vExpertCommunity WarriorsUser Moderators

                    What is confusing ? How to run it ?

                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 7. Re: Command or script needed to get Datastore, NAA identifier and multipath
                      CRad14 Hot Shot

                      Make sure you are running the whole thing...Including the first line I listed

                       

                      "$datastore=get-datastore"

                       

                      I just tried it again for my stuff and it looks fine

                       

                      Also I am sure LucD's stuff would work as well

                      • 8. Re: Command or script needed to get Datastore, NAA identifier and multipath
                        jessem Enthusiast

                        I ran it but it opens up the csv with 0 data in it.  I copied and pasted this code, just replaced the cluster name with my cluster.

                         

                        ---------

                        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 $'windows 01' | 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

                        • 9. Re: Command or script needed to get Datastore, NAA identifier and multipath
                          jessem Enthusiast

                          hmmm, that line is definitely part of the .ps1 script and yet the csv file has nothing in there...

                           

                           

                          Capture.PNG

                           

                           

                          $datastore=get-datastore

                           

                          $disks=get-cluster 'OS 01' | get-vmhost | get-scsilun -luntype disk

                          $entry=@()

                          $output=@()

                          ForEach ($disk in $disks)

                           

                           

                          {

                          $entry="" | Select DataStorename, Canonicalname, Multipathing

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

                          $entry.canonicalname=$disk.canonicalname

                          $entry.multipathing=$disk.multipathpolicy

                          $output+=$entry

                          }

                           

                          $output | Export-csv c:\lun_multipath.csv

                          • 10. Re: Command or script needed to get Datastore, NAA identifier and multipath
                            LucD Guru
                            Community WarriorsUser ModeratorsvExpert

                            You should save the script in a .ps1 file, let's say Lun-report.ps1.

                            Then from the PowerCLI prompt you call it with parameters

                            ./Lun-report.ps1 -ClusName MyCluster -CsvName "C:\report.csv"

                            Did you run it like that ?

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 11. Re: Command or script needed to get Datastore, NAA identifier and multipath
                              LucD Guru
                              Community WarriorsvExpertUser Moderators

                              The Extent property is an array. Try replacing that line with this

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

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 12. Re: Command or script needed to get Datastore, NAA identifier and multipath
                                jessem Enthusiast

                                yes, can you show me how the code would look if my cluster name is WINDOWS 01?  Maybe I don't have it correctly listed/placed?

                                • 13. Re: Command or script needed to get Datastore, NAA identifier and multipath
                                  LucD Guru
                                  Community WarriorsvExpertUser Moderators

                                  Sure, it should be started like this

                                  ./Lun-report.ps1 -ClusName "WINDOWS 01" -CsvName "C:\report.csv"

                                  Do you get any error messages ?

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 14. Re: Command or script needed to get Datastore, NAA identifier and multipath
                                    jessem Enthusiast

                                    yes, here is the error:

                                     

                                    Get-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

                                    At C:\users\a\desktop\Lun-report.ps1:13 char:26

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

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

                                        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster

                                     

                                     

                                    You cannot call a method on a null-valued expression.

                                    At C:\users\a\desktop\Lun-report.ps1:15 char:55

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

                                        + CategoryInfo          : InvalidOperation: (Split:String) [], RuntimeException

                                        + FullyQualifiedErrorId : InvokeMethodOnNull

                                     

                                     

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

                                    At C:\users\a\desktop\Lun-report.ps1:26 char:24

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

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

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

                                     

                                     

                                    Get-Datastore : Cannot validate argument on parameter 'RelatedObject'. The argument is null or empty. Supply an argument that is not null or empty and then try the comm

                                    nd again.

                                    At C:\users\a\desktop\Lun-report.ps1:36 char:26

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

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

                                        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetDatastore

                                     

                                     

                                    Get-Cluster : Cannot validate argument on parameter 'Name'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.

                                    At C:\users\a\desktop\Lun-report.ps1:46 char:12

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

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

                                        + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetCluster

                                    1 2 Previous Next