Expert Solutions: Beginner Event 5 of the 2010 Scripting Games

ScriptingGuy1

Bookmark and Share

 

(Note: These solutions were written for Beginner Event 5 of the 2010 Scripting Games.) 

 

Beginner Event 5 (Windows PowerShell)

Photo of Laerte Poltronieri Junior

Laerte Poltronieri Junior is a MCDBA—DBA SQL Server and can be found at the following:

·         www.laertejuniordba.spaces.live.com

·         www.simple-talk.com/author/laerte-junior

·         www.twitter.com/laertejuniordba

·         SQL Server Powershell Extension Team: http://sqlpsx.codeplex.com/

 

I wrote this script using the advanced functions and parameter ComputerName as ValueFromPipeline = $ true to enable the receiving values from the pipe if there is more than one computer to be displayed. I also used the Win32_Processor Class as a basis for displaying the description of the family.

I needed a simple and objective way to make an inventory of all computers of the company. The major requirements were the CPU data, family, and manufacturer. Additionally, it is used to display the CPU speed at the moment.

Here is the script.

function get-CpuInfo

{

      param (

                  [Parameter(Position=0, Mandatory=$false, ValueFromPipeline = $true)] [string] $ComputerName = $env:computername

                 

              )

             

      Begin

      {

     

            function ConvertTo-CPUCaption($Value)

            {

                  switch($value)

                  {

                        1   {“Other”;break}

                        2   {“Unknow”;break}

                        3   {“8086”;break}

                        4   {“80286”;break}

                        5   {“Intel386™ Processor”;break}

                        6   {“Intel486™ Processor”;break}

                        7   {“8087”;break}

                        8   {“80287”;break}

                        9   {“80387”;break}

                        10  {“80487”;break}

                        11  {“Pentium Brand”;break}

                        12  {“Pentium Pro”;break}

                        13  {“Pentium II”;break}

                        14  {“Pentium Processor with MMX™ Technologyr”;break}

                        15  {“Celeron™”;break}

                        16  {“Pentium II Xeon™”;break}

                        17  {“Pentium III”;break}

                        18  {“M1 Family”;break}

                        19  {“M2 Family”;break}

                        24  {“AMD Duron™ Processor Family”;break}

                        25  {“K5 Family”;break}

                        26  {“K6 Family”;break}

                        27  {“K6-2”;break}

                        28  {“K6-3”;break}

                        29  {“AMD Athlon™ Processor Family”;break}

                        30  {“AMD2900 Family”;break}

                        31  {“K6-2+”;break}

                        32  {“Power PC Family”;break}

                        33  {“Power PC 601”;break}

                        34  {“Power PC 603”;break}

                        35  {“Power PC 603+”;break}

                        36  {“Power PC 604”;break}

                        37  {“Power PC 620”;break}

                        38  {“Power PC X704”;break}

                        48  {“Alpha Family”;break}

                        49  {“Alpha 21064”;break}

                        50  {“Alpha 21066”;break}

                        51  {“Alpha 21164”;break}

                        52  {“Alpha 21164PC”;break}

                        53  {“Alpha 21164a”;break}

                        54  {“Alpha 21264”;break}

                        55  {“Alpha 21364”;break}

                        64  {“MIPS Family”;break}

                        65  {“MIPS R4000”;break}

                        66  {“MIPS R4200”;break}

                        67  {“MIPS R4400”;break}

                        68  {“MIPS R4600”;break}

                        69  {“MIPS R10000”;break}

                        80  {“SPARC Family”;break}

                        81  {“SuperSPARC”;break}

                        82  {“microSPARC II”;break}

                        83  {“microSPARC IIep”;break}

                        84  {“UltraSPARC”;break}

                        85  {“UltraSPARC II”;break}

                        86  {“UltraSPARC IIi”;break}

                        87  {“UltraSPARC III”;break}

                        88  {“UltraSPARC IIIi”;break}

                        96  {“68040”;break}

                        97  {“68xxx Family”;break}

                        98  {“68000”;break}

                        99  {“68010”;break}

                        100 {“68020”;break}