0

Can you help me with my Powershell script? I am fairly new to Powershell but my boss wants me to get this done soon.

For each VM on our HyperVisor (Server 2012) we want the associated VHD files and for each VHD file:
- The location of the file
- The size of the file (max allowed)
- The actual size of the file (current allocated)
- The type of allocation: thick or thin
- The location of the snapshot file
- The size of the snapshot file

I have come up with this so far (well.. what I've found)(* is our HV name):

Get-VM –ComputerName ***** | 
Get-VMHardDiskDrive | 
Select-Object -Property VMName, ComputerName, Path, Filesize, Size, Disktype, Snapshot | 
Sort-Object -Property VMName 

Somehow this doesnt give any output for Filesize, disktype, size and Snapshot..

4

2 回答 2

1

加载 HyperV 模块。运行“'Get-VM”以查看它是否已加载。然后运行这样的东西:

Get-VM –ComputerName SERVER1, SERVER2 |
Get-VMHardDiskDrive |
Select-Object -Property VMName, VMId, ComputerName, ControllerType, ControllerNumber, ControllerLocation, Path |
Sort-Object -Property VMName |
Out-GridView -Title "Virtual Disks"
于 2014-02-14T14:24:04.890 回答
0

这个问题已经很老了,但也许有人对此感兴趣。

注意:不考虑快照

$VMget=Get-VM -computername w01s007,w01s006,w01s008 | Get-VMHardDiskDrive | Select-Object -Property vmname, vmid, computername, controllertype, controllernumber,controllerlocation,path
 foreach ($VM in $VMget) {
    $VHDRemotePath=$VM.Path  -replace ":", "$"
    $VHDRemotePath="\\"+$VM.ComputerName+"\"+$VHDRemotePath
    $vhdsize=  gci $VHDRemotePath | select-object @{Name="SizeGB";Expression={"{0:N2}" -f ($_.length / 1GB)}}
    write-host = $VM.VMName " - " $vhdsize.SizeGB "GB - " $VM.Path
}
于 2016-10-18T12:50:08.827 回答