locked
Powershell script not getting memory values RRS feed

  • Question

  • Hello Forum

    I have a PowerShell script that loops through a set of servers to get the TotalPhysicalMemory, FreePhysicalMemory and Page File stats: -

    $TimeStamp=Get-Date -format "dd-MMM-yyyy HH:mm:ss"

    $ServerSpecs=Get-WmiObject -Class Win32_OperatingSystem -computername $server

    $MemoryCapacity=$ServerSpecs.TotalPhysicalMemory

    $MemoryAvailable = $ServerSpecs.FreePhysicalMemory

    $PageFile = Get-WmiObject Win32_PageFileUsage -computername $server

    $PageFileMaxSize = $PageFile.AllocatedBaseSize

    $PageFileUsed=$PageFile.CurrentUsage

    However when I run the script no values are being returned for $MemoryCapacity or $MemoryAvailable

    Can anyone advise where I am going wrong here?

    Many thanks


    Please click "Mark As Answer" if my post helped. Tony C.

    Monday, October 9, 2017 11:13 AM

Answers

  • Thanks Paolo

    I ended up using this: -

    $ServerSpecs=Get-WmiObject win32_OperatingSystem -computername $server

    $MemoryCapacity=$ServerSpecs.TotalVisibleMemorySize

    $MemoryAvailable = $ServerSpecs.FreePhysicalMemory

     


    Please click "Mark As Answer" if my post helped. Tony C.

    • Marked as answer by Anthony C-UK Monday, October 9, 2017 1:24 PM
    Monday, October 9, 2017 12:13 PM

All replies

  • Hi Antony,

        you can use:

    Get-WMIObject -class Win32_PhysicalMemory

    or 

    get-ciminstance -class "cim_physicalmemory" | % {$_.Capacity}

    Regards

    Monday, October 9, 2017 11:46 AM
  • Thanks Paolo

    I ended up using this: -

    $ServerSpecs=Get-WmiObject win32_OperatingSystem -computername $server

    $MemoryCapacity=$ServerSpecs.TotalVisibleMemorySize

    $MemoryAvailable = $ServerSpecs.FreePhysicalMemory

     


    Please click "Mark As Answer" if my post helped. Tony C.

    • Marked as answer by Anthony C-UK Monday, October 9, 2017 1:24 PM
    Monday, October 9, 2017 12:13 PM