Sunday

Memory And CPU Check Script

Hi,

Today I have created one powershell script which is useful to diagnose high CPU and Memory Consumption on Windows Server..


Code------

========================================================================




#Memory And CPU Check Script by Prashant SHalgar; 2014#

  
        $scripthost = Read-Host 'Enter 1 for Memory or 2 for CPU';
        ""
        "Server Diagnostics"
 "{code}"
        if ($scripthost -match "1")
         {

            #Memory and CPU Check Script by Prashant Shalgar#





#Top 10 Processes using Physical Memory #

"The Top 10 Processes using Physical Memory are:"


Get-Process | Sort-Object -Property "WS" -desc | Select-Object -First 15
"
#Total and Available Physical Memory"
systeminfo | findstr "Memory"
}



Elseif 
($scripthost -match "2")
{  #Top 10 Processes using CPU #


echo "The Top 10 Processes using CPU are:"

Get-Process | Sort-Object -Property "CPU" -desc | Select-Object -First 15
" "
"#Load On CPU"
Get-WmiObject win32_processor | select LoadPercentage



Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average -maximum -minimum | Select
}

else
  {
  Write-Host -BackgroundColor White -ForegroundColor Red "INVALID ENTRY! Please try again."
  }
 
 "
  " 


"{code}"

###################################################################
 "#All User Sessions On This Server"
"{code}"
query session
"{code}"


Read-Host -Prompt "Press Enter to exit"



========================================================================

0 Responses to “Memory And CPU Check Script”

Post a Comment

Windows Admin Jobs in Pune