Hello guys,
I'm trying to export VM information from Vcenter who then will be imported in our CMDB. One of this information is regarding GuestOS partition.
Im nearly there ... It's just cosmetic
get-vm "myVM" | select @{N="partition";E={foreach ($Disk in (Get-VM $_).Extensiondata.Guest.Disk){$Disk.Diskpath,([math]::Round($Disk.Capacity /1024MB),'GB')}}}
Here's the result
partition : {C:\, 50 GB, E:\, 70 GB...}
Can you help me having :
- All partitions informations instead of the first 2 and then "..."
- Remove the "{" and the "}" in the output
- Remove the space between "50" and "GB" for all partitions.
- Remove the "," between drive letter and size
The goal is to have the result formatted like that :
C:\ 50GB, E:\ 70GB, F:\ 100GB
Thx
Raf
Here's the result
D:\ 14.754878997802734375 GB,C:\ 49.656246185302734375 GB
Based on your suggestion i was able to adapt my first idea. This one output exactly what i want
Get-VM "MyVM" | Select @{N='Path';E={((get-vm $_).extensiondata.Guest.Disk | sort $_.Diskpath | %{" $($_.diskPath) $([math]::Round($_.Capacity /1024MB)) GB"}) -join ','}}
Output :
C:\ 50GB, D:\ 15GB
Thx a lot
Raf
Would this work?
foreach($vm in Get-VM){
$vm.Guest.Disks |
Select @{N='VM';E={$vm.Name}},
Path,
@{N='SizeGB';E={"{0:N0} GB" -f $_.CapacityGB}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Luc,
If you don't mind, could you explain how you found $vm.Guest.disks
I too was able to find it by tabbing from $vm. to $vm.guest to $vm.guest.disk
but is there a way to get all available options cause otherwise I'm just guessing?
You can use the PowerCLI Cmdlet Reference.
Under the VirtualMachine object, you can click through all the properties.
Another option is to use the Format-Custom cmdlet with the Depth parameter.
Get-VM -Name MyVM | Format-Custom -Depth 2
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc, thats going to help me so much in the future, great tip!
Cheers
Hello Luc,
Unfortunately not.
It need to be on one line because I have a lot of things exported
Like that
get-vm "MyVM" | select @{N="partition";E={foreach ($Disk in (Get-VM $_).Extensiondata.Guest.Disk){$Disk.Diskpath,([math]::Round($Disk.Capacity /1024MB),'GB')}}}
To have a result like that (everything on one line)
C:\ 50GB, D:\ 100GB, E:\ 110GB
Thx
Try like this
Get-VM |
Select Name,
@{N='Path';E={($_.Guest.Disks | %{"$($_.Path) $($_.CapacityGB) GB"}) -join ','}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's the result
D:\ 14.754878997802734375 GB,C:\ 49.656246185302734375 GB
Based on your suggestion i was able to adapt my first idea. This one output exactly what i want
Get-VM "MyVM" | Select @{N='Path';E={((get-vm $_).extensiondata.Guest.Disk | sort $_.Diskpath | %{" $($_.diskPath) $([math]::Round($_.Capacity /1024MB)) GB"}) -join ','}}
Output :
C:\ 50GB, D:\ 15GB
Thx a lot
Raf
This code doesn't seem to sort the partitions properly. If you change it to the following, it works properly:
Get-VM "MyVM" | Select @{N='Path';E={((get-vm $_).extensiondata.Guest.Disk | Sort DiskPath | %{" $($_.DiskPath) $([math]::Round($_.Capacity /1024MB)) GB"}) -join ','}}
Great thread. This really helped me.