Powershell WMI scripting help

Hyper-V PowerShell Scripting Issue

I need to Modify my script to compensate for the following : Total Memory of All Hyper-V Hosts (*combined Total*)

I need to Add a calculation for Node Loss to this script:

I am open to suggestions on this, however a base calculation would be *Total Memory Pooled* / 256GB
As the Avg of my Hosts have 256 GB RAM.

#Total Count of Physical CPU Cores
#Total Count of In use CPU Cores
#Total COunt of Available CPU Cores

$cred = Get-Credential
$serverList  =               Get-ADComputer -Filter "Name -like '*SERVER*'" | Select-Object -ExpandProperty Name

#Get Hyper-V Fail-Over Information
$HyperVFailoverInfo = Invoke-Command -ComputerName $serverList -Credential $cred -ScriptBlock {
    $vmhost = Get-CimInstance -computername $serverList -ClassName Win32_OperatingSystem -ErrorAction Stop
    $win32ProcessorList = Get-WmiObject -Class Win32_Processor
    $vMList = Get-VM
    $freePhysicalMemory = [Math]::Round(($vmhost.FreePhysicalMemory / 1MB), 2)
    $totalPhysicalMemory = [Math]::Round(((Get-WMIObject -Class Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum / 1gb), 2)
    $totalInUseMemory = [Math]::Round(($TotalPhysicalMemory - $FreePhysicalMemory), 2)
    $TotalCPUCoresInUseRM = ($vMList | Where-Object {$_.State -eq 'Running'} | Get-VMProcessor | Measure-Object -Property Count -Sum).Sum
    $TotalCPUCoresInUse = ($vMList | Where-Object {$_.State -eq 'Running'} | Get-VMProcessor | Measure-Object -Property Count -Sum).Sum
    $logicalCpuCount = ($win32ProcessorList | Measure-Object -Property NumberOfLogicalProcessors -Sum).Sum
    $totalCPUCoresInUse = (Get-VM | Measure-Object -Property Count -Sum).Sum
    $TotalPooledMemory = $null
    $TotalNodeLoss = $null
    #$TotalPooledMemory = () # Total Memory of All Hyper-V Hosts (Combined)
    #$TotalNodeLoss =   Total Pooled Memory / 256GB

'' | Select-Object -Property `
    @{n = 'Computername'; e = {$ENV:ComputerName}},
    @{n = 'Free Physical Memory GB'; e = {$FreePhysicalMemory}},
    @{n = 'In Use Physical Memory GB'; e = {$totalInUseMemory}},
    @{n = 'Total Physical Memory GB'; e = {$TotalPhysicalMemory}},
    @{n = 'Total Node Loss'; e = {$TotalNodeLoss}},
    @{n = 'TotalPooledMemory'; e = {$TotalPooledMemory}},
    @{n = 'Total Processors'; e = {$logicalCpuCount}},
    @{n = 'TotalVirtualCPUsInUse (running Machines)'; e = {$TotalCPUCoresInUseRM}},
    @{n = 'TotalVirtualCPUsInUse (All Allocated including Stopped)'; e = {$TotalCPUCoresInUs}},
    @{n = 'Total Processors Available';	e = {$logicalCpuCount - $totalCPUCoresInUse}}

} |

Select-Object -Property * -ExcludeProperty PSComputerName, RunspaceId |
    Sort-Object -Property ComputerName, VMName

write-host "Exported Hyper-V Failover Information to c:\Temp\"
$HyperVFailoverInfo | Export-Csv -NoTypeInformation -Path $HyperVFailoverFileName
$HyperVFailoverInfo | Out-GridView

Open in new window

LVL 15
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ben Personick (Previously QCubed)Lead Network EngineerCommented:
Well, invoke is a job and all, but you'll be increasing total pooled memory at each returned result.

 Why would you want total pooled memory and number of failovers as a separate column since they will be the same data throughout?

The easiest way would be to write those separately.  Otherwise, you'll have to create a new object and list its results along with the parsed results from the summation.

To sum the physical memory to get a max:
$TotalPooledMemory = $($HyperVFailoverInfo | Measure-Object "Total Physical Memory GB" -Sum).Sum
$TotalNodeLoss = [Math]::Round(($TotalPooledMemory / 256), 0)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben Personick (Previously QCubed)Lead Network EngineerCommented:
glad to help :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.