01 / MODEL A WINDOWS FLEET · LESSON 02

Read hardware without losing the units

Build a reusable capacity function that distinguishes installed, visible, and free memory.

12 min · learn at your pace

Three memory numbers answer different questions

The simulated OS follows the property units of Win32_OperatingSystem: FreePhysicalMemory and TotalVisibleMemorySize are kilobytes. The hardware object's TotalPhysicalMemory follows Win32_ComputerSystem and is bytes. Mixing those scales produces convincing but incorrect capacity reports.

PowerShell's 1MB and 1GB constants are binary multipliers. A kilobyte-valued OS property divided by 1MB becomes GiB; a byte-valued hardware property divided by 1GB becomes GiB. Keep those units in the output property names. Use floating-point arithmetic so fractions survive.

Installed is not the same as available

InstalledGiB describes the fixture's physical memory; VisibleGiB is smaller because the scenario reserves memory. FreeGiB describes a point-in-time observation. It does not predict future application headroom. On a real machine, physical-memory module capacities can provide a more precise installed total than the computer-system aggregate.

Cores and logical processors

The fixture also separates physical cores from logical processors. app01 has two cores and four logical processors; web01 has two of each. Do not multiply these values or call both “CPUs”. Your function should preserve both fields.

Accept the threshold as a parameter. A server with exactly the requested free memory meets the minimum. The checks call your function with different hosts and thresholds so a hard-coded report is insufficient.

Go deeper

Read the official reference.

Try an example.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
Get-LabHardware app01
(Get-LabOperatingSystem app01).FreePhysicalMemory / 1MB
YOUR TURN

Put it into practice.

Define Get-FleetCapacity(ComputerName, MinimumFreeGiB=2). Return ComputerName, InstalledGiB, VisibleGiB, FreeGiB, Cores, LogicalProcessors, and boolean MeetsMinimum. Compare free memory with an inclusive minimum. Define the function without printing a demo report.

See an explained solution
One way to solve it.ps1
Import-Module '/home/user/LabFleet.psm1' -Force
function Get-FleetCapacity {
    param([string]$ComputerName, [double]$MinimumFreeGiB=2)
    $os=Get-LabOperatingSystem $ComputerName
    $hardware=Get-LabHardware $ComputerName
    $free=[double]$os.FreePhysicalMemory / 1MB
    [pscustomobject]@{
        ComputerName=$ComputerName; InstalledGiB=[double]$hardware.TotalPhysicalMemory / 1GB
        VisibleGiB=[double]$os.TotalVisibleMemorySize / 1MB; FreeGiB=$free
        Cores=$hardware.NumberOfCores; LogicalProcessors=$hardware.NumberOfLogicalProcessors
        MeetsMinimum=($free -ge $MinimumFreeGiB)
    }
}

Explicit conversions preserve the distinction between installed, OS-visible, and currently free memory. Parameterised thresholds make the same function useful to different teams.