vin01
Expert
Expert

report with vmname,lun name,vmdkfile path and nna

Hi guys

I need a script to generate report of vmname,lunname,vmdkfile path and nna

i am having the below script but here i am missing nna info please correct this missing string

$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="Datacenter";E={$Datacenter.name}},

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

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

          @{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},

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

      }

    }

  }

}

$VmInfo

Regards Vineeth.K
LucD
Leadership
Leadership

Try like this

$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="Datacenter";E={$Datacenter.name}},
         
@{N="Cluster";E={$Cluster.Name}},
         
@{N="Hard Disk";E={$HardDisk.Name}},
         
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
         
@{N="CanonicalName";E={
            [
string]::Join(',',((Get-Datastore -Name ($HardDisk.FileName.Split("]")[0].TrimStart("["))).Extensiondata.Info.Vmfs.Extent | %{$_.DiskName}))}},
         
@{N="VMDKpath";E={$HardDisk.FileName}}
      }
    }
  }
}
$VmInfo


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

vin01
Expert
Expert

but here i am not getting datastore name and CanonicalName

these fields it is showing blank

Regards Vineeth.K
Reply
0 Kudos
LucD
Leadership
Leadership

My mistake, I assumed the VIproperties module was loaded.

I updated the script above, please try again.


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

View solution in original post

Reply
0 Kudos
vin01
Expert
Expert

thanks a lot LucD.it works for me..

Regards Vineeth.K
EdisonL
Contributor
Contributor

Hi Luc,

I tried this but got nothing, C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts> .\scriptname.ps1 >>c:\myfile.csv. I save your script as scriptname.ps1.

What did I miss?

Thank you!

Reply
0 Kudos
LucD
Leadership
Leadership

You do have a connection to a vSphere Server open I assume ?

Check $global:defaultviserver

Anything displayed on screen when you leave out the redirection to the file ?

Any error message ?


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

Reply
0 Kudos
EdisonL
Contributor
Contributor

Hi Luc,

My bad. I needed to wait till it finishes the query. I have around 50 VMs, so need time to complete the script. Thank you for this excellent script. Btw, I will need to checkout this from my wishlist, VMware vSphere PowerCLI Reference: Automating vSphere Administration: 9780470890790: Computer Scienc...  Smiley Happy

Best regards!

Reply
0 Kudos