none
Powershell - combing entries RRS feed

  • Question

  • 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


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    Blog: http://www.windows-support.co.uk  Twitter:   LinkedIn:

    Tuesday, May 26, 2015 9:35 AM

Answers

  • $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
    Tuesday, May 26, 2015 2:23 PM

All replies

  • $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
    Tuesday, May 26, 2015 2:23 PM
  • 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
    Tuesday, May 26, 2015 2:25 PM
  • 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


    Regards,

    Denis Cooper

    MCITP EA - MCT

    Help keep the forums tidy, if this has helped please mark it as an answer

    Blog: http://www.windows-support.co.uk  Twitter:   LinkedIn:

    • Proposed as answer by Josh Lavely Wednesday, May 27, 2015 10:42 AM
    Wednesday, May 27, 2015 4:57 AM
  • My apologies , just fixed it.
    • Edited by Josh Lavely Wednesday, May 27, 2015 9:34 AM Fixed original post
    Wednesday, May 27, 2015 9:32 AM