Powershell - combing entries

HI,

Not to sure how to accomplish this and I've not done much with powershell for a little while now so was hoping to get some help.

Basically I need to do a quick capacity plan against a Hyper-V estate. The bit I am struggling with is getting the disk size for disks in the virtual machines and if they are dynamic or not. I have the script lines to do this, but the command doesn't return the virtual machine name.

So basically I want to combine the output of two scripts into one file.

This script line gets the Virtual Machines in the farm

Get-VM -VMMServer SP-SCVM02 | Select-Object ComputerName,Name,TotalSize,VMCPath

This line reads the Virtual Disk information

Get-SCVirtualHardDisk -VMMServer "SP-SCVM02" -vm $_.name | Select-Object VHDType,MaximumSize,Size

What I need to do is create a file (or output) that has the columns from both outputs together, so I can tie the Virtual Disks to the Computername.

Get-VM -VMMServer SP-SCVM02 | Select-Object ComputerName,Name,TotalSize,VMCPath | Foreach {
	Get-SCVirtualHardDisk -VMMServer "SP-SCVM02" -vm $_.name | Select-Object VHDType,MaximumSize,Size
	}

Any help appreciated.

thanks

Denis

May 26th, 2015 5:37am

$mastertable=$null
$table=$null
$vm=$null
$VM=Get-VM -VMMServer SP-SCVM02 | Select-Object ComputerName,Name,TotalSize,VMCPath 
Foreach ($V in $VM){
	$info=Get-SCVirtualHardDisk -VMMServer "SP-SCVM02" -vm $v 
	               $Table=[PSCustomObject][Ordered]@{
                                                    VM = $V.computername
                                                    "VM Total Size" = $V.totalsize
                                                    VMCPath = $v.VMCPath
                                                    "VHD Type" = $Info.VHDType
                                                    "Maximum Size" = $Info.MaximumSize
                                                    Size = $Info.Size
                   
                                                    }
                   $MasterTable += $table
                   }
                   
 ## Display to screen
 $Mastertable
 ## Output to file
 $Mastertable | Out-File C:\Temp\VMInfo.csv

Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 10:25am

HI,

Not to sure how to accomplish this and I've not done much with powershell for a little while now so was hoping to get some help.

Does the below get what you would like returned? Let me know and we can tweak/ edit this to make it how you want.

May 26th, 2015 10:27am

$mastertable=$null
$table=$null
$vm=$null
$Mastertable=@()
$VM=Get-VM -VMMServer SP-SCVM02 |
Foreach ($V in $VM){
	$info=Get-SCVirtualHardDisk -VMMServer "SP-SCVM02" -vm $v 
	               $Table=[PSCustomObject][Ordered]@{
                                                    VM = $V.computername
                                                    "VM Total Size" = $V.totalsize
                                                    VMCPath = $v.VMCPath
                                                    "VHD Type" = $Info.VHDType
                                                    "Maximum Size" = $Info.MaximumSize
                                                    Size = $Info.Size
                   
                                                    }
                   $MasterTable += $table
                   }
                   
 ## Display to screen
 $Mastertable
 ## Output to file
 $Mastertable | Out-File C:\Temp\VMInfo.csv



  • Proposed as answer by Josh Lavely 21 hours 34 minutes ago
  • Edited by Josh Lavely 21 hours 34 minutes ago Fixed original post
  • Marked as answer by Denis Cooper 19 hours 5 minutes ago
Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 2:23pm

$mastertable=$null
$table=$null
$vm=$null
$Mastertable=@()
$VM=Get-VM -VMMServer SP-SCVM02 |
Foreach ($V in $VM){
	$info=Get-SCVirtualHardDisk -VMMServer "SP-SCVM02" -vm $v 
	               $Table=[PSCustomObject][Ordered]@{
                                                    VM = $V.computername
                                                    "VM Total Size" = $V.totalsize
                                                    VMCPath = $v.VMCPath
                                                    "VHD Type" = $Info.VHDType
                                                    "Maximum Size" = $Info.MaximumSize
                                                    Size = $Info.Size
                   
                                                    }
                   $MasterTable += $table
                   }
                   
 ## Display to screen
 $Mastertable
 ## Output to file
 $Mastertable | Out-File C:\Temp\VMInfo.csv



  • Proposed as answer by Josh Lavely Wednesday, May 27, 2015 9:35 AM
  • Edited by Josh Lavely Wednesday, May 27, 2015 9:36 AM Fixed original post
  • Marked as answer by Denis Cooper Wednesday, May 27, 2015 12:05 PM
May 26th, 2015 2:23pm

HI,

Not to sure how to accomplish this and I've not done much with powershell for a little while now so was hoping to get some help.

Does the below get what you would like returned? Let me know and we can tweak/ edit this to make it how you want.

  • Edited by Josh Lavely Tuesday, May 26, 2015 2:25 PM Typo
Free Windows Admin Tool Kit Click here and download it now
May 26th, 2015 2:25pm

HI,

Not to sure how to accomplish this and I've not done much with powershell for a little while now so was hoping to get some help.

Does the below get what you would like returned? Let me know and we can tweak/ edit this to make it how you want.

  • Edited by Josh Lavely Tuesday, May 26, 2015 2:25 PM Typo
May 26th, 2015 2:25pm

Thanks,

it doesn't seem to work though - I just get the below error message foreach $v

Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition

Free Windows Admin Tool Kit Click here and download it now
May 27th, 2015 12:59am

My apologies , just fixed it.
  • Edited by Josh Lavely 21 hours 36 minutes ago Fixed original post
May 27th, 2015 5:33am

My apologies , just fixed it.
  • Edited by Josh Lavely Wednesday, May 27, 2015 9:34 AM Fixed original post
Free Windows Admin Tool Kit Click here and download it now
May 27th, 2015 9:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics