Sunday, 18 July 2010

Get-Performance.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script displays basic performance information for a computer 
  4. .DESCRIPTION 
  5.     This script calls Get-Counter on a computer to obtain default  
  6.     performance counters. These are obtained and displayed. The script 
  7.     takes a parameter which is the host name to display. 
  8. .NOTES 
  9.     File Name  : Get-Performance.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell Version 2.0 
  12. .LINK 
  13.     This script posted to: 
  14.         http://www.pshscripts.blogspot.com 
  15. .EXAMPLE 
  16.     PSH [C:\foo]: .\Get-Performance.ps1 
  17.     Basic Performance for system: Cookham8 
  18.      Network Bytes Per Second (2 adapters) 
  19.        broadcom netxtreme gigabit etherne          0.00 kbps 
  20.        netgear fa311v2 pci adapter                 8.15 kbps 
  21.      CPU Usage                                     1.93 % 
  22.      Committed Bytes                              30.61 mb 
  23.      Cache Faults                                  0.00 p/s 
  24.      Percent Disk Time                            34.15 % 
  25.      Disk Queue length                             0.00 
  26. .EXAMPLE 
  27.     PSH [C:\foo]: .\Get-Performance cookham2 
  28.     Basic Performance for system: cookham2 
  29.      Network Bytes Per Second (6 adapters) 
  30.        public                                     25.31 kbps 
  31.        broadcom netxtreme 57xx gigabit co         26.20 kbps 
  32.        internal                                    0.16 kbps 
  33.        isatap.cookham.net                          0.00 kbps 
  34.        teredo tunneling pseudo-interface           0.00 kbps 
  35.        isatap.{0b3c0adc-3418-4842-8b4e-cf          0.00 kbps 
  36.      CPU Usage                                     0.39 % 
  37.      Committed Bytes                              45.80 mb 
  38.      Cache Faults                                  0.00 p/s 
  39.      Percent Disk Time                             0.00 % 
  40.      Disk Queue length                             0.00 
  41. .PARAMETER comp 
  42.     The name of the computer to display. Default is localhost. 
  43. #> 
  44.  
  45. param
  46. [string] $comp = "localhost" 
  47.  
  48. # Get counters 
  49. $counter = Get-Counter -computername $comp 
  50.  
  51. #Display results 
  52. "Basic Performance for system: {0}" -f $comp 
  53.  
  54. # Network interface
  55. $c= $counter.countersamples | where {$_.path -match "network Interface"
  56. " Network Bytes Per Second ({0} adapters)" -f $c.count 
  57. foreach ($ni in $c){ 
  58.   $nin = if ($ni.instancename.length -le 34)  {$ni.InstanceName} 
  59.          else {$ni.instancename.substring(0,34)} 
  60.  
  61.  "   {0,-35} {1,12:n2} kbps" -f $nin,$($ni.cookedvalue/1kb) 
  62.  
  63. # CPU Usage 
  64. $c= $counter.countersamples | where {$_.path -match "processor time"
  65. " CPU Usage           {0,30:n2} %" -f $c.cookedvalue 
  66.  
  67. # Memory 
  68. $cb = ($counter.countersamples | where {$_.Path -match "bytes in use"}).cookedvalue 
  69. $cf = ($counter.countersamples | where {$_.Path -match "cache"}).cookedvalue 
  70. " Committed Bytes     {0,30:n2} mb" -f $cb 
  71. " Cache Faults        {0,30:n2} p/s" -f $cf 
  72.  
  73. # Disk 
  74. $dt =  ($counter.countersamples | where {$_.Path -match "disk time"}).cookedvalue 
  75. $dql = ($counter.countersamples | where {$_.Path -match "queue"}).cookedvalue 
  76. " Percent Disk Time     {0,30:p2}" -f $dt 
  77. " Disk Queue Length   {0,30:n2}" -f $dql 

No comments: