- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
but here i am not getting datastore name and CanonicalName
these fields it is showing blank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot LucD.it works for me..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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... ![]()
Best regards!