Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Updated 3-Jul-12 2:40am

1 solution

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:[^]
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900