2009-06-10

Powershell Scripting Games - Day 2

Here is my solution for Day 2 - Beginner

All the information is retrieved from WMI

   1: #First we get the info from WMI
   2: $computer = "Localhost"
   3: $mycomp = Get-WmiObject Win32_Processor -ComputerName $computer
   4:  
   5:  
   6: # We Output our Info
   7:  
   8: Write-Host -ForegroundColor Green "Strength Evaluation for" $computer 
   9: Write-Host -ForegroundColor Yellow "Speed:" $mycomp.MaxClockSpeed"Mhz"
  10: Write-Host -ForegroundColor Yellow "L2 Cache Size:" $mycomp.L2CacheSize
  11:     #We will check if the data is null or not
  12:     if ($mycomp.L2CacheSpeed -eq $null) {
  13:         $L2CacheSpeed = "Data is not Available"
  14:         Write-Host -ForegroundColor Red "L2 Cache Speed:" $L2CacheSpeed
  15:     }
  16:     else {
  17:         $L2CacheSpeed = $mycomp.L2CacheSpeed
  18:         Write-Host -ForegroundColor Yellow "L2 Cache Speed:" $L2CacheSpeed
  19:     }    
  20: Write-Host -ForegroundColor Yellow "L3 Cache Size:" $mycomp.L3CacheSize
  21:     #We will check if the data is null or not
  22:     if ($mycomp.L3CacheSpeed -eq $null) {
  23:         $L3CacheSpeed = "Data is not Available"
  24:         Write-Host -ForegroundColor Red "L3 Cache Speed:" $L3CacheSpeed
  25:     }
  26:     else {
  27:         $L3CacheSpeed = $mycomp.L3CacheSpeed
  28:         Write-Host -ForegroundColor Yellow "L3 Cache Speed:" $L3CacheSpeed
  29:     }    
  30: Write-Host -ForegroundColor Magenta "Strength ..."
  31: Write-Host -ForegroundColor Magenta "Number of Cores:" $mycomp.NumberOfCores
  32: Write-Host -ForegroundColor Magenta "Number of Logical Cores:" ` 
  33:     $mycomp.NumberOfLogicalProcessors
  34: Write-Host -ForegroundColor Magenta "Processor Name:" $mycomp.Name
  35: Write-Host -ForegroundColor Cyan "Agility ..."
  36: Write-Host -ForegroundColor Cyan "Adress Width:" $mycomp.AddressWidth