VMware Cloud Community
Veen86
Contributor
Contributor

VM partition information

hi,

I have made a script to read out Partition information of a set of VM's and write it to a Csv. it works great except if I have a VM with multiple Partitions, I can't get that to work. Can someone help me with this?

this is my Script:

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

# #

  1. Author: Fons Biemans 29/04/2009 #

  2. objective: #

  3. Scan Disks of VM's #

  4. Write result to Csv file #

  5. #

# #

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

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

  1. VMware VirtualCenter server name #

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

$vcserver="MYVIRTUAL"

$portvc="443"

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

  1. Add VI-toolkit #

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

Add-PSsnapin VMware.VimAutomation.Core

Initialize-VIToolkitEnvironment.ps1

connect-VIServer $vcserver -port $portvc

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

  1. Variables #

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

$ErrorActionPreference = "SilentlyContinue"

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

  1. Functions #

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

function FreeSpace

{

param($vm)

::Round( ($vm.FreeSpace/1024/1024/1024),1 )

}

function Capacity

{

param($vm)

::Round( ($vm.Capacity /1024/1024/1024),1 )

}

function Full

{

param($vm)

::Round( (($vm.Capacity - $vm.FreeSpace)/1024/1024/1024),1 )

}

function ProcFree

{

param($vm)

::Round( ( 100 * ( $vm.FreeSpace / $vm.Capacity ) ),0 )

}

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

  1. Percentage freespace on partitions in the VM #

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

$myCol = @()

$SBPs= Get-Content "server.txt"

foreach ($SBP in $SBPs)

{

$On= Get-VM $SBP | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks

$myObj = "" | Select-Object VmName, Path, FreeSpace,Capacity,Full, PercFree

$myObj.VmName = $On| Select VmName

$myObj.Path = $On | Select Path

$myObj.FreeSpace = FreeSpace $On

$myObj.Capacity = Capacity $On

$myObj.Full = Full $On

$myObj.PercFree = ProcFree $On

$myCol += $myObj

}

$myCol| Sort PercFree | Export-Csv C:\test.csv

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

  1. Disconnect session from VC #

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

disconnect-viserver -confirm:$false

0 Kudos
1 Reply
alanrenouf
VMware Employee
VMware Employee

I wrote something similar recently in one line.

http://www.virtu-al.net/2009/03/25/vi-toolkit-one-liner-vm-guest-disk-sizes/

Looking at your script you will need to do another loop to loop through each of the disks it recieves, this will still work for 1 disk too.

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos