Automation

 View Only
Expand all | Collapse all

Get Complete Inventory PowerCLI

  • 1.  Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 02:16 AM

    Below is a script that does exactly what I want but I need to make some changes to it and need help adding the needed lines. I will like to add a line to show the LUN ID's for each storage LUN on each hosts and also add a line for WWN names of the hosts as well. Below is the script.

    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)) {
           
    "" | Select-Object -Property @{N="VM";E={$VM.Name}},
           
    @{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
           
    @{N="VM CPU Core#";E={$vm.NumCPU}},
           
    @{N="Datacenter";E={$Datacenter.name}},
           
    @{N="Cluster";E={$Cluster.Name}},
           
    @{N="Host";E={$vm.VMHost.Name}},
           
    @{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
           
    @{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
           
    @{N="Hard Disk";E={$HardDisk.Name}},
           
    @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
           
    @{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:\scripts\reports\report.csv"

    Re: Get Complete Inventory PowerCLI



  • 2.  RE: Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 08:24 PM

    While retrieving that info is not too hard, how do you want to show this in the output objects.

    The script will produce an object (or line in the CSV file) per harddisk.

    Do you want to add that LUN info on each harddisk line ?

    I think it would be more readable if you collect that LUN info in a separate CSV.

    What do you think ?



  • 3.  RE: Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 08:30 PM

    Thanks for you response. I will like to have both meaning LUN ID on the main list and also separate so that I can compare or use the separate one for other analysis.



  • 4.  RE: Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 08:30 PM

    Forgot to add that yes I will want the LUN info on each harddisk line.



  • 5.  RE: Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 08:54 PM

    To make sure I get that, you want to list each LUN and all the HBA WWN on the ESXi server on the harddisk line ?

    That will be an overcrowded line I suspect.



  • 6.  RE: Get Complete Inventory PowerCLI

    Posted Jul 19, 2013 09:00 PM

    They want a complete report and I tried to let them know but they insisted. Like I mentioned before, I will like both scenarios and will separate when needed.

    Thanks



  • 7.  RE: Get Complete Inventory PowerCLI

    Posted Jul 21, 2013 01:19 PM

    LuCD, any update on this?



  • 8.  RE: Get Complete Inventory PowerCLI

    Posted Jul 22, 2013 07:33 AM

    Try it like this.

    Note, since you didn't specify which WWN you want to include in the report, I took the Target WWN.

    $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="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
           
    @{N="VM CPU Core#";E={$vm.NumCPU}},
           
    @{N="Datacenter";E={$Datacenter.name}},
           
    @{N="Cluster";E={$Cluster.Name}},
           
    @{N="Host";E={$vm.VMHost.Name}},
           
    @{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
           
    @{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
           
    @{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:\scripts\reports\report.csv"



  • 9.  RE: Get Complete Inventory PowerCLI

    Posted Jul 24, 2013 07:53 PM

    Hi LucD,

    I ran the script and it errored out on me. Attached is the error.



  • 10.  RE: Get Complete Inventory PowerCLI

    Posted Jul 24, 2013 08:27 PM

    It looks like you didn't do a Connect-VIserver before you ran the script.



  • 11.  RE: Get Complete Inventory PowerCLI

    Posted Jul 24, 2013 08:29 PM

    Just took a lot at the error and spotted that. My bad.

    Just restarted it again. I think it will take a couple of hours as I started one on another sever about 4 hours ago.



  • 12.  RE: Get Complete Inventory PowerCLI

    Posted Jul 25, 2013 02:49 PM

    Hi LucD,

    The cript seems to be running for more than 6 hours. I will like to remove some lines from it and just have it get me information about VM hosts, VM's, WWN names of the hosts and the LUN ID of whatever is presented from the storage array. What I'm trying to get is the LUN ID that I can tie to each VM through the host. We are trying to identify what VM and hosts are tied to specific LUN iD's. Below is the script;

    $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