Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 185574

Re: Get Complete Inventory PowerCLI

$
0
0

Hi LucD,

 

Below is the updated script which I modified. I just want it to give me the LUN ID's of the storage array mapped to each ESX and what VM's are associated with it. Let me know if it's correct.

 

Thanks,

 

 

$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {

  ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {

    ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {

      ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name))

{

        $ds = Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("[")) |

          Select -First 1

        $dsLun = @()

        $dsLunID = @()

        $dsWwwn = @()

        Get-ScsiLun -Datastore $ds | Sort-Object -Property CanonicalName -Unique | %{

          $dsLun += $_.CanonicalName

          $dsLunID += $_.RunTimeName.Split(':')[-1].Trim('L')

        }

        $esx = Get-VMHost -Name $vm.VMHost.Name

        $lunKey = @()       

        $lunKey = $esx.ExtensionData.Config.StorageDevice.ScsiLun |

          where {$dsLun -contains $_.CanonicalName} | %{$_.Key}

        $lunWWN = @()

        $lunWWN = $esx.ExtensionData.Config.StorageDevice.MultipathInfo.Lun |

          where {$lunKey -contains $_.Lun} | %{

            $_.Path | %{"{0:x}" -f $_.Transport.NodeWorldWideName}

          } | Sort-Object -Unique

        "" | Select-Object -Property @{N="VM";E={$VM.Name}},

        @{N="Datacenter";E={$Datacenter.name}},

        @{N="Cluster";E={$Cluster.Name}},

        @{N="Host";E={$vm.VMHost.Name}},

        @{N="Hard Disk";E={$HardDisk.Name}},

        @{N="Datastore";E={$ds.Name}},

        @{N="LUN";E={[string]::Join(',',$dsLun)}},

        @{N="LUNID";E={[string]::Join(',',$dsLunId)}},

        @{N="LUNWWN";E={[string]::Join(',',$lunWWN)}},

        @{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},

        @{N="VMDKpath";E={$HardDisk.FileName}},

        @{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-

 

 

flat.")}).size/1GB}},

        @{N="Drive Size";E={$HardDisk.CapacityGB}}

      }

    }

  }

}

$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\temp\WWNCF03-LUNIDreport.csv"


Viewing all articles
Browse latest Browse all 185574

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>