Get VHD Info from all hosts

Dec 4, 2009 at 7:04 PM

Hi,

I have 5 servers with hyperv, and i want to know the space of the vhd in each vm

With the script i have the size of the vhds of the server than i run the script.-

Get-VMDisk | foreach { if ($_.DriveName -eq "Hard Drive") {$env:vhd=$_.Diskpath}; Get-VHDInfo -vhdPath $env:vhd | Format-Table FullName, FileSize, MaxInternalSize, TypeName -AutoSize }

how i do to obtain the size of remote servers.

thanks

 

 

Coordinator
Dec 8, 2009 at 10:53 PM

Get-VMDisk doesn't support -server , [I can't see why I did

What you can do is

Get-vm -server Server1,Server2,Server3   | get-vmDiskController | get-vmDriveByController | get-VMdiskByDrive | foreach-object {Get-vhdinfo -server $_.__server -vhdpath $_.connection[0] } | format-table

 

Dec 11, 2009 at 3:23 PM


JAMESONE

I run what the script but it didn't work.

Get-WmiObject : Not supported
At C:\Program Files\Modules\hyperv\Disk.ps1:621 char:40
+ $VMRASD = Get-WmiObject <<<< -ComputerName $Server -Namespace $HyperVNamespace -Query "ASSOCIATORS OF {$_} where ResultClass = MSVM_ResourceAllocationSe
ttingData"
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

If I run the script for the local server there's no problem, the problem appears when i try to run it to a remote server.

my script

Get-vm -server otherserver | get-vmDiskController |
get-vmDriveByController | get-VMdiskByDrive |
foreach-object {Get-vhdinfo -server $_.__server -vhdpath $_.connection[0]} |
Format-Table __Server, FullName, @{label=?FileSize(GB)?; Expression={?{0:N2}? -f ($_.FileSize/1024mb)}}, @{label=?MaxInternalSize(GB)?; Expression={?{0:N2}? -f ($_.MaxInternalSize/1024mb)}}, TypeName -autosize

thanks


----Mensaje original----
De: notifications@codeplex.com
Fecha: 08/12/2009 19:53
Para:
Asunto: Re: Get VHD Info from all hosts [PSHyperv:77152]

pre {font-size:1.25em;}

From: jamesone

Get-VMDisk doesn't support -server , [I can't see why I did

What you can do is

Get-vm -server Server1,Server2,Server3 | get-vmDiskController | get-vmDriveByController | get-VMdiskByDrive | foreach-object {Get-vhdinfo -server $_.__server -vhdpath $_.connection[0] } | format-table


</BLOCKQUOTE
Dec 21, 2009 at 12:47 AM

JAMESONE

I run what the script but it didn't work.

Get-WmiObject : Not supported
At C:\Program Files\Modules\hyperv\Disk.ps1:621 char:40
+ $VMRASD = Get-WmiObject <<<< -ComputerName $Server -Namespace $HyperVNamespace -Query "ASSOCIATORS OF {$_} where ResultClass = MSVM_ResourceAllocationSe
ttingData"
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

If I run the script for the local server there's no problem, the problem appears when i try to run it to a remote server.

my script

Get-vm -server otherserver | get-vmDiskController |
get-vmDriveByController | get-VMdiskByDrive |
foreach-object {Get-vhdinfo -server $_.__server -vhdpath $_.connection[0]} |
Format-Table __Server, FullName, @{label=?FileSize(GB)?; Expression={?{0:N2}? -f ($_.FileSize/1024mb)}}, @{label=?MaxInternalSize(GB)?; Expression={?{0:N2}? -f ($_.MaxInternalSize/1024mb)}}, TypeName -autosize

 thanks a lot

Coordinator
Jan 8, 2010 at 6:13 PM

I'm looking at this now - hopefully in a day or so you will be able to use get-vmDisk with multiple servers.

 

Jan 13, 2010 at 8:33 PM

Thanks

but now i have another problem what i want you know

When i ran the script Get-VMDisk -server server01 | foreach { if ($_.DriveName -eq 'Hard Drive') {Get-VHDInfo -server $_.__Server -vhdPath $_.Diskpath}} * Server01 is not the server where i ran the script.

I had a error message:

Split-Path : Cannot find drive. A drive with the name 'E' does not exist.
At line:1 char:14
+ ($(Split-Path <<<<  $VHDPath) -eq "")
    + CategoryInfo          : ObjectNotFound: (E:String) [Split-Path], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SplitPathCommand

I think the error is in the line: 482 from disk.ps1 (if ($(Split-Path $VHDPath) -eq "") {$VHDPath = Join-Path $(Get-VhdDefaultPath $Server) $VHDPath }), for me the error comes becouse in the server02 where i ran the script didn't had the drive E:\

I coment the line and it works fine.

 

 

 

 

 

 

 

 

Coordinator
Jan 14, 2010 at 7:05 PM

Ah....

OK that is the last bug fix / enhancement for this build. I've gone through and replaced split-path everywhere.