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:
######################################
# #
Author: Fons Biemans 29/04/2009 #
objective: #
Scan Disks of VM's #
Write result to Csv file #
#
# #
######################################
####################################
VMware VirtualCenter server name #
####################################
$vcserver="MYVIRTUAL"
$portvc="443"
##################
Add VI-toolkit #
##################
Add-PSsnapin VMware.VimAutomation.Core
Initialize-VIToolkitEnvironment.ps1
connect-VIServer $vcserver -port $portvc
#############
Variables #
#############
$ErrorActionPreference = "SilentlyContinue"
#############
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 )
}
##################################################
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
##############################
Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false
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