none
powershell script to capture server memory RRS feed

Answers

  • The script will run until you stop it, you can also use the -MaxSamples switch to define how many times it will run.

    For multiple computers you can for example use:

    $MemoryUsage = "\memory\% committed bytes in use"

    $MemoryUsage | Get-Counter -Computer Server01, Server02, Server03 -SampleInterval 300 -MaxSamples 288 | Out-File C:\Temp\MemoryUsage.txt

    (If you have the interval of 5 minutes, you can have 288 samples in one day)

    If you want to append data to an existing file, you can use the Add-Content PowerShell cmdlet.

    Example

    $MemoryUsage | Get-Counter -Computer Server01, Server02, Server03 -SampleInterval 300 | Add-Content -Path C:\Temp\MemoryUsage.txt

    You can also trigger the script with Scheduled Tasks.


    Blog: https://thesystemcenterblog.com LinkedIn:


    • Edited by Leon Laude Wednesday, November 14, 2018 2:12 PM
    • Marked as answer by KIRUBAKARAN J A Wednesday, November 14, 2018 2:17 PM
    Wednesday, November 14, 2018 2:11 PM

All replies

  • Hi,

    You can use the Get-Counter PowerShell cmdlet and then use the -SampleInterval switch to assign how often it should capture the memory.

    Example

    Get-Counter "\\YourComputer\memory\% committed bytes in use" -SampleInterval 300 | | Out-File C:\Temp\MemoryUsage.txt
    (Above example captures the memory used every 5 minutes)

    Best regards,
    Leon


    Blog: https://thesystemcenterblog.com LinkedIn:

    Wednesday, November 14, 2018 1:00 PM
  • hi leon,

    it's  running,

    Get-Counter "\\EDI-SERVER\memory\% committed bytes in use" -SampleInterval 300 | Out-File D:\backups\Memory\MemoryUsage.txt


    how to append record with existing .txt file  ( i want to keep single txt file holds all captures)

    Wednesday, November 14, 2018 1:17 PM
  • The script will run until you stop it, you can also use the -MaxSamples switch to define how many times it will run.

    For multiple computers you can for example use:

    $MemoryUsage = "\memory\% committed bytes in use"

    $MemoryUsage | Get-Counter -Computer Server01, Server02, Server03 -SampleInterval 300 -MaxSamples 288 | Out-File C:\Temp\MemoryUsage.txt

    (If you have the interval of 5 minutes, you can have 288 samples in one day)

    If you want to append data to an existing file, you can use the Add-Content PowerShell cmdlet.

    Example

    $MemoryUsage | Get-Counter -Computer Server01, Server02, Server03 -SampleInterval 300 | Add-Content -Path C:\Temp\MemoryUsage.txt

    You can also trigger the script with Scheduled Tasks.


    Blog: https://thesystemcenterblog.com LinkedIn:


    • Edited by Leon Laude Wednesday, November 14, 2018 2:12 PM
    • Marked as answer by KIRUBAKARAN J A Wednesday, November 14, 2018 2:17 PM
    Wednesday, November 14, 2018 2:11 PM
  • i used append key

    Get-Counter "\\EDI-SERVER\memory\% committed bytes in use" -SampleInterval 300 | Out-

    File -Append D:\backups\Memory\MemoryUsage.txt

    Wednesday, November 14, 2018 2:17 PM