Automation

 View Only
  • 1.  Count resources

    Posted Jan 26, 2023 07:24 AM

    Hi Team,

    I am running below command :

    Get-Folder Test | Get-VM

    I got output with Powerstate,Num Cpus and Memory

    How to add condition to check if both of VM having same count of cpu and memory

    I want a output to mention same count of cpu and memory and if not, need mention whether cpu is not match or memory

     



  • 2.  RE: Count resources

    Posted Jan 26, 2023 07:52 AM

    Your request is a bit confusing (for me at least).
    What exactly do you want to see in the output?
    Perhaps show a mockup?



  • 3.  RE: Count resources

    Posted Jan 26, 2023 08:06 AM
      |   view attached

    When running below command:

    Get-Folder Test | Get-VM

    I got output as per attached with CPU count and Memory size.

    Screen shot attached.

    I would like to add a Comparison, if the vm in the folder list having same cpu and memory size or not.

    And extract it as a report, so i can know which folder having vm  resource mismatch



  • 4.  RE: Count resources

    Posted Jan 26, 2023 08:27 AM

    I know what Get-VM produces as output, my question is about the "... extract it as a report"
    What do you envisage seeing in such a report?



  • 5.  RE: Count resources

    Posted Jan 26, 2023 08:33 AM

    To identify and count how many VM in the folder having different cpu and memory.

    Later will assign all vm in the folder with same cpu and memory



  • 6.  RE: Count resources
    Best Answer

    Posted Jan 26, 2023 08:44 AM

    You mean like this?

    Get-Folder -Name Test | Get-VM |
    Group-Object -Property NumCPu, MemoryGB |
    ForEach-Object -Process {
      New-Object -TypeName PSObject -Property ([ordered]@{
          NumCPu =[int]($_.Name.Split(',')[0])
          MemoryGB = [int]($_.Name.Split(',')[1])
          Count = $_.Group.Count
          VM = $_.Group.Name -join '|'
        })
    }