Click here to Skip to main content
12,756,437 members (31,543 online)
Rate this:
Please Sign up or sign in to vote.
See more: PowerShell
How to use PowerShell script that will show the free space on the C: drive of your virtual windows machine.

Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer localhost | Select SystemName,DeviceID,VolumeName,@{Name="Size(GB)";Expression={[decimal]("{0:N1}" -f($_.size/1gb))}},@{Name="Free Space(GB)";Expression={[decimal]("{0:N1}" -f($_.freespace/1gb))}},@{Name="Free Space(%)";Expression={"{0:P2}" -f(($_.freespace/1gb) / ($_.size/1gb))}} | Out-GridView -Title "Drive Space"

This code just can show the local machine. How to show the virtual window machine?
Posted 3-Jul-12 3:39am
Evan Ng101
Updated 3-Jul-12 3:40am
Tim Corey116.3K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You will need to have network access to your virtual machine if you want to use this particular script. Once you set up your virtual machine to be on your local network like any other physical machine, you can then access it via name or IP address. You would change the "-computer localhost" to be "-computer {VM_MachineName}". Just make sure your VM has its firewall open to accept this type of connection.

If you want to connect to the Virtual Machine host software and get the space of the running virtual machines that way, you will need a different script. Those are usually specific to which type of Virtual Machine hypervisor you use. Here is a forum with a couple different examples that might be relevant to your situation:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 3 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100