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:
http://communities.vmware.com/message/1701655[
^]