VMware Cloud Community
Pyrochaser
Contributor
Contributor
Jump to solution

Guest OS Diskspace report from a list of Imported VMs

So I am trying to compile a list of OS Disk Space from VMs listed in a CSV. I have seen other posts about reporting diskspace for all VMs in a vcenter, however in this case I would like to be more granular by isolating and reporting on the VMs I manage.

Below is a script I was able to find on the community however this pulls all VMs rather then the select few I have listed in my CSV. So far I have come up with how to create a variable with for each object, but my PowerCLI scripting experience is limited and I am not confident that this is the best approach. Anyone have any suggestions? Can I use the VM Info Script but touch up a few points in the script to display the disk info for my $vmlist variable only? Thanks for any help or suggestions.

$vmlist = Import-Csv "c:\Dump\VMSServers.csv" | ForEach-Object -Process {$_.Vmlist}

##################

# VM information #

##################

$Report= @()

connect-VIServer -server xxx -user "xxx" -password "xxx"

$vmguest = Get-VM | Get-VMguest | where {$_.State -eq "Running"}

foreach($vm in $vmguest){

     foreach($disk in $vm.disks){

     $report += Select-Object -InputObject $vm, $disk -Property @{N="VMName";E={$vm.vmname}},

                          @{N="Path";E={$disk.path}},

                          @{N="CapacityGB";E={[math]::Round(($disk.Capacity)/1GB)}},

                          @{N="FreespaceGB";E={[math]::Round(($disk.FreeSpace)/1GB)}},

                          @{N="MemoryMB";E={$vm.vm.memorymb}},

                          @{N="NumCPU";E={$vm.vm.numcpu}}

}}

$report | Export-Csv "C:\vmreport.csv" -NoTypeInformation -UseCulture

Disconnect-VIServer -Server xxx -Confirm:$false

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

In that case change the first line into this

$vmlist = Import-Csv "c:\Dump\VMSServers.csv" | %{$_.VMName}



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

View solution in original post

0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

##################

# VM information #

##################

$vmlist = Import-Csv "c:\Dump\VMSServers.csv"

$Report= @()

connect-VIServer -server xxx -user "xxx" -password "xxx"

$vmguest = Get-VM -Name $vmlist | Get-VMguest | where {$_.State -eq "Running"}

foreach($vm in $vmguest){

     foreach($disk in $vm.disks){

     $report += Select-Object -InputObject $vm, $disk -Property @{N="VMName";E={$vm.vmname}},

                          @{N="Path";E={$disk.path}},

                          @{N="CapacityGB";E={[math]::Round(($disk.Capacity)/1GB)}},

                          @{N="FreespaceGB";E={[math]::Round(($disk.FreeSpace)/1GB)}},

                          @{N="MemoryMB";E={$vm.vm.memorymb}},

                          @{N="NumCPU";E={$vm.vm.numcpu}}

}}

$report | Export-Csv "C:\vmreport.csv" -NoTypeInformation -UseCulture

Disconnect-VIServer -Server xxx -Confirm:$false


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

Pyrochaser
Contributor
Contributor
Jump to solution

LucD so I tried what you recommended and I think based off this error it might be the way I have my CSV set up:

PCLIerror.png

So that being said my CSV has Row One Column A as VMName Similar to what is pasted below:

csvVM.png

I am guessing changing the layout of the CSV will resolve the above error? Thanks for your input btw.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

In that case change the first line into this

$vmlist = Import-Csv "c:\Dump\VMSServers.csv" | %{$_.VMName}



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

0 Kudos
Pyrochaser
Contributor
Contributor
Jump to solution

And this LucD, is why you are the OMG, Holy Crap, Most Epic, Super Awesome Scripter! Thanks a million LucD. Worked beautifully.

LucD.png

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Lol

blushing_smiley_face_4.jpg


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

0 Kudos