VMware Cloud Community
Venkat_A
Enthusiast
Enthusiast

Script for increase the C drive for 40% free space!!

Hi,

In our org I have requirement like,

Its a C drive expansion project.

1. First need to check the C drive, if the free space is less than 40% (>40%) then we need to make sure the free space is 40%.

So, Can I get some script for this. I have more than 1000 vm's, so it is hard for me to do it manually.

Thanks

0 Kudos
3 Replies
Venkat_A
Enthusiast
Enthusiast

I got this script

function DriveSpace {

param( [string] $strComputer)

"$strComputer ---- Free Space (percentage) ----"

# Does the server responds to a ping (otherwise the WMI queries will fail)

$query = "select * from win32_pingstatus where address = '$strComputer'"

$result = Get-WmiObject -query $query

if ($result.protocoladdress) {

    # Get the Disks for this computer

    $colDisks = get-wmiobject Win32_LogicalDisk -computername $strComputer -Filter "DriveType = 3"

    # For each disk calculate the free space

    foreach ($disk in $colDisks) {

       if ($disk.size -gt 0) {$PercentFree = [Math]::round((($disk.freespace/$disk.size) * 100))}

       else {$PercentFree = 0}

  $Drive = $disk.DeviceID

       "$strComputer - $Drive - $PercentFree"

       # if  < 40% free space, log to a file

       if ($PercentFree -le 40) {"$strComputer - $Drive - $PercentFree" | out-file -append -filepath "d:\Drive_Space.txt"}

    }

}

}

foreach ($computer in cat d:\vmslist.txt) {DriveSpace "$computer"}

0 Kudos
LucD
Leadership
Leadership

You could run that script locally inside the guest OS of the VM through the Invoke-VMScript cmdlet.


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

0 Kudos
Venkat_A
Enthusiast
Enthusiast

Can you please guide me Lucd. I am new to Powercli, just learning now Smiley Sad

0 Kudos