Quantcast
Channel: Hey, Scripting Guy! Blog
Viewing all 3333 articles
Browse latest View live

Beginner Leaderboard of the 2012 Scripting Games After 9 Days

$
0
0

This is the Beginner leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day, as event submissions are graded by the judges. All entries will continue to be graded by judges until 12:01 A.M. Pacific Time (UTC-8) on April 23, 2012. At that time, no more scripts will be evaluated, and the leaderboard will be finalized.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Beginner Events

User Name

Total Points

Scripts Rated

Total Ratings

Lido Paglia

43.25

9

20

Mike F Robbins

41.95

9

29

Sahal Omer

41.67

9

19

Dawn Villejoin

41.57

9

29

arnold moreno

40.87

9

20

Mr_Motown

40.17

9

24

Cliff Harrison

39.75

9

23

wschoier

39.67

9

16

Srikanth

39.5

9

22

Chris Manning @pbchris

39.33

9

20

yellowscope

39.17

9

22

JeffWouters

39.13

9

30

Andy Mello

39

9

20

Eric Pankowski

39

9

21

Matt benton

38.83

9

20

Adam Funck

38.75

9

20

Don Hunt

38.67

9

19

ScriptingWife

38.42

9

25

Grzegorz Kulikowski

38.33

9

18

Nathan Mayberry

38.17

9

16

ckrull

37.92

9

25

qsilverx

37.9

9

22

Jordan Davis

37.83

9

22

Neil Clinch

37.75

8

16

Chris-D

37.5

9

20

Maciej

37.5

9

22

TechguyTJ

37.5

9

20

Paul Hiles

37.33

9

20

Eleftheria Theologou

37.27

9

20

CraigJahnke

37.17

9

18

Daniel Killian

37

9

21

Duffman

37

9

25

Charlie Jacobson

37

9

20

James McNeil

36.92

9

19

Tim Muessig

36.92

9

23

JoeTea

36.75

9

17

Marcin Pietras

36.67

8

14

James Berkenbile

36.67

9

21

Sigitas Grėbliūnas

36.5

8

16

David Waderich

36.33

9

18

Brian Bohanon

36.25

9

21

mark_@_li

36.17

9

17

NCoppersmith

36.17

9

18

Alexis Ragual

36

8

17

James White

36

9

24

David OBrien

36

9

17

GCaporale

36

9

24

mtb44

36

9

21

jaydee

36

9

19

AballahSonDis

36

9

19

Jhonny Yamaniha

35.92

9

20

Thiyagu

35.83

8

15

ngebhar2

35.83

9

21

Steven Neel

35.67

8

14

John Grenfell

35.58

9

20

Vinay Bhandari

35.58

9

18

Werner

35.25

9

23

tyoung

35.25

9

23

Jeremy Cox

35.17

9

21

Erica Miles

35.17

9

23

Joshua Taylor

35.1

9

24

Julie Andreacola

35.08

9

19

Michael Moore

35

9

19

L4NM4N

35

9

22

clbarnett

35

9

21

AmandaD

34.92

9

20

ICC_jruff

34.83

9

17

NakiPS1

34.83

9

21

Nadeem Vance

34.83

9

18

Fabio Jr

34.67

9

17

cemarsh06

34.67

9

22

Brian Sabatini

34.33

9

21

Steve Hall

34.33

9

18

Shaun Watts

34.25

9

19

Tim Watson

34.2

9

22

SLevenberg

34.17

9

18

blahcubed

34

8

13

Matt Tilford

34

9

22

Mark P

33.92

8

19

Ifiok Moses

33.83

9

21

BTmuney

33.83

9

23

Andy Bidlen

33.67

8

18

Lotte

33.67

9

20

John Russell

33.67

9

19

rumart

33.5

9

22

SM Yeoh

33.5

9

19

TSCSG

33.5

9

19

ruskie

33.42

8

18

Dominic Leonard

33.42

9

17

Chris Seiter

33.33

9

16

Jason Y.

33.33

9

21

David Christian

33.33

9

19

Andrey Zvyagin

33.25

9

18

Rich Oswald

33.17

9

18

Ken Wilson

33.17

9

23

Xander Solis

33

9

23

ICC_mworthley

33

9

23

MikeHowden

32.92

8

16

Dave Maldonado

32.92

8

15

Jon McCormick

32.92

9

23

Oleg Suchkov

32.9

9

20

SdeDot

32.83

9

22

John OHarra

32.82

9

23

James Stallwood

32.75

8

18

Shevek

32.67

9

17

Pradeep Rawat

32.67

9

23

honeybadger

32.5

8

16

emekm

32.5

9

17

Wouter Beens

32.42

9

19

Daniel Thompson

32.33

9

21

Andreas Engkvist

32.33

9

20

eribaq

32.27

9

21

Dexter Dhami

32.25

8

16

Derek Schauland

32.17

8

18

BradC

32.17

9

20

NSlearningPS

32

9

16

Elmerp

31.83

9

16

DrLe

31.75

8

20

Zak Humphries

31.58

8

18

DaveyK

31.42

9

22

Max Schnell

31.33

7

14

Timo Skupin

31.33

9

24

Leon Nell

31.33

9

23

Mads Hjort Larsen

31.33

9

20

dluke001

31.08

9

20

Daniel Bicho

31.08

9

21

Daniel Dittenhafer

31

9

20

The Awesome-Machine.NET

31

9

18

Jess Pomfret

31

9

20

Phill McSherry

30.83

8

20

ICC_RichardEisenberger

30.75

9

23

Tyson J. Hayes

30.67

9

17

Nate Shepard

30.67

9

18

Riwe

30.67

9

21

Nathan Lare

30.5

8

15

andre

30.5

8

18

Yves PASCAULT

30.5

9

18

Norman Manoh

30.5

9

17

Carl

30.42

8

22

mvanhorenbeeck

30.42

8

20

Geathan

30.37

9

19

Robert B

30.17

9

20

Stephen Correia

30.17

9

16

Aaron Bednar

30

9

18

BreakDown

30

9

24

JeremyB

29.92

9

21

member2712

29.83

9

19

Roy M

29.67

8

17

John

29.6

8

17

Matt Swint

29.58

8

19

nyoro2

29.5

7

14

AnotherPoShBlog

29.4

8

18

Nisha Sridhar

29.33

7

14

Scott Baker

29.08

8

19

cphair

29

8

12

Will Nevis

28.75

9

21

therceg

28.67

8

15

eklime

28.58

7

17

Marty

28.3

8

20

TheKidd

28

7

9

Scott Alvarino

28

8

18

Daniel Snowden

27.92

8

16

Dan

27.92

8

17

NGelotte

27.67

6

13

MOW

27.5

8

16

W. Sterling

27.5

8

19

aaron d

27.5

9

19

real fastcomputer

27.5

9

17

Andrew Morgan

27.42

7

18

shiv

27.42

8

19

Dennis James

27.33

7

12

Zia

27.33

8

19

Gica

27.15

7

18

Mouton

27.08

8

19

Pendrag

27

7

11

Matt McAllister

27

8

19

Stephen Brown

26.67

7

13

Vern Anderson

26.67

9

21

BernhardG

26.5

7

15

mand0

26.33

7

13

Mod10

26.33

9

23

Clayton McKenzie

26.25

8

20

Joe Keohan

26

9

17

Chuck Lathrope

25.77

8

18

erunama

25.75

9

22

ResetSA

25.67

8

18

Sidewinder

25.5

7

18

Tony Rad

25.5

8

20

aalaminos

25.42

7

18

Sai Prasad Vaddepally

25.33

7

14

catremor

25.25

7

17

MarkIsBack

25.17

7

17

something easier to read

24.58

7

18

BenJT

24.5

7

18

Clancy Wendt

24.33

8

19

jones89

24.17

8

20

mrgif1

24

6

10

oki

23.5

7

12

Jason Omar

23.25

6

18

ICC_KFoley

23.17

7

20

Kryten-68

23

7

17

Emil Eriksson

23

7

15

Brian Fraley

22.92

7

16

Derrick Michelson

22.83

7

16

Mathieu Boulard

22.75

5

15

Steve Mahoney

22.75

7

17

Kieran Walsh

22.67

7

14

kloinerFeigling83

22.58

8

17

octavmarius

22.17

5

12

robert broyles

21.83

7

13

jarheadf23

21.75

6

13

Trevor Watkins

21.5

7

17

Shawn Melton

21.33

5

12

Chris Keim

21.33

6

14

mnadobnik

21.25

6

13

Tony Uren

21

6

13

Vinay Thakur

20.83

9

19

Japke

20.5

6

14

e46d8dd2e1625c7a6182b82bc012a7e0

20.5

8

19

Luke Forder

19.92

5

16

jbrek

19.83

6

13

Megha Kuruvilla

19.67

5

12

EDW

19.5

6

10

HitchHeik

19.17

6

15

Jeff Schulman

19

5

11

Marcos Tsuda

18.92

7

13

Mooseade

18.8

5

14

vNiklas

18.75

5

13

Shawn bequette

18.33

6

12

Daniel Headley

18.17

5

10

toumi walid

18.17

6

18

John van Leeuwen

17.58

6

14

Andrew Dauncey

17.33

5

10

Bastien B

16.5

5

16

Mckie

15.47

6

14

Niel Fletcher

15

5

10

Richard Holman

14.5

4

8

Colyn1337

14

3

4

ed3c64f9163ea026e949706ee53b2a34

14

5

8

Shaun Gibbs

14

6

11

lamaar75

13.33

5

13

Matt Vidrine

12

3

8

Chris Albert

11.33

3

6

Patrik Lindström

10.5

3

9

Bret Ridenour

10.5

4

12

Hov Arve

10.17

4

9

vbscripter

9

2

3

joeartz

9

2

6

Darren Maspero

9

2

8

Peter Heydon

8.92

2

7

Tim Miller

8.67

3

11

DWS

8.42

2

7

Dennis Jarjosa

8.42

2

7

plindgren

8.42

3

11

Yuri Kutovoy

8.42

3

11

Matt_A_

8.42

3

9

lvimeux

8.33

2

6

Jan R.

8.33

2

6

Arif Ali

8.33

3

10

Anders Wang

8.33

3

6

Jerame Caudill

8

2

6

Thomas Farmer

8

2

6

TomKupka

7.83

3

11

sfibich

7.75

2

7

Francisco Puig Diaz

7.75

3

11

Bryan

7.67

2

4

Mark Amann

7.67

2

6

Forrest Stanley

7.67

2

6

Name

7.6

3

10

Tomek A.

7.5

2

8

MarcoB78

7.42

2

7

TaylorGibb

7.4

2

8

Kevin

7.33

3

8

Michael Odermatt

7.08

2

7

Jeffrey Jacobs

7

2

6

Clinton Merritt

7

2

5

Greg Combs

7

3

7

Sander

6.83

2

7

Scott Button

6.83

2

7

Tom Parker

6.67

2

6

Paul Sweeney

6.5

2

4

Coderaven

6.33

2

5

u2tb

6.33

2

6

Clayton Firth

6.25

2

7

Jeff Maes

6

2

6

Harshul

6

2

3

Benduru

6

3

4

sebuko

5.75

2

6

greeme

5.67

2

6

Apnea

5.67

2

6

Satheesh

5.67

2

7

Timm Brochhaus

5.5

2

6

Jonny Earl Grey Lindbom

5.47

2

8

radek

5.42

2

7

Josh Nylander

5.42

2

7

TheZmann

5.33

2

4

Dave Baird

5.33

2

6

RJSN

5.33

2

4

DisplayName

5.33

2

5

Anthony Rum

5.25

2

7

Mike Lambert

5.25

2

7

Andrew Cameron

5

1

3

foobar

5

1

1

Dean Grant

5

1

3

Andy Wyse

5

2

7

Brian Wuchner

5

2

8

Joel Cook

5

2

6

JMARCH

5

2

2

Mallika Gogulamudi

5

2

8

acchong

4.75

1

4

Sudeep Bhaskar

4.5

1

4

Ken King

4.5

1

2

Petter Edin

4.33

2

6

Andrew Gardner

4.25

1

4

Jason Schmidtlein

4.25

1

4

Ryan Youngs

4

1

3

zacd

4

1

3

Claymonster

4

1

3

Francisco osorio

4

1

3

Filip Rejch

4

1

2

James B. Bizzell

4

1

2

Jay Lockard

4

1

3

evidence

4

1

3

Pavan Hotha

4

1

3

PSLearner

4

2

6

peter bishop

4

2

8

Björn

4

2

2

Dominic Daigle

3.85

2

9

Ola Skjeldal

3.67

1

3

Tim Hetzel

3.67

1

3

Brett Chandler

3.67

1

3

Chris Watson

3.67

2

5

Bob__Mule

3.5

1

4

Brendan Erofeev

3.5

1

4

sgatepunk

3.5

1

2

ocongil

3.33

1

3

Jasper van der Heijden

3.33

1

3

Tobias

3.33

1

3

70f53217af68ac357dfc1a46739257a6

3.33

1

3

MonitorMan

3.33

1

3

iTodd

3.33

1

3

Jonathan Birkett

3.33

1

3

redi311

3.33

1

3

Dexter

3.33

2

6

b4d93r

3.33

2

5

jeprus

3.25

1

4

Jakob Bindslet

3

1

3

skynetx

3

1

3

Crystal Diaz

3

1

3

Jude Croyle

3

1

3

Andrew Newman

3

1

3

mitch baker

3

1

3

miramar_unna

3

1

2

MrBatchFile

2.67

2

6

Jeremy Dunlop

2.33

1

3

a64c64bd8e1fe90b8b024ab272090e32

2.33

1

3

Daed

2.33

1

3

Jay mac

2.33

1

3

Byty

2

1

3

Nico

1.75

1

4

3166f9ba33499b4658123e7b0a84598f

1.67

1

3

Luca Christmann

1.67

1

3

le4ne

1.5

1

4

Sean Massey

1.33

1

3

David Granlund

1.33

1

3

Anjan Chidurala

1.33

1

3

Chris Nakagaki (Zsoldier)

1.33

1

3

2e638c99ea54b4ddb208033083f4ef24

1.33

1

3

Gabriel Tapia

1.33

1

3

Marcin Kowalczyk

1.33

1

3

j.vogt

1.33

1

3

TitleRequired

1.33

1

3

John Main

1.33

1

3

Jason Shaw

1.25

1

4

Eric Ray

1.25

1

4

Gary Jackson

1.25

1

4

gary gray

1.2

1

5

TechJLS3

1

1

5

WizardX

1

1

5

Jeremy Kieler

1

1

3

 


Randomly Drawn Prize Winners: 2012 Scripting Games Day 9

$
0
0

Thank you for entering the 2012 Scripting Games. A special thank you to our wonderful sponsors for making these prizes possible. Please be sure to visit the sponsors page for more information about these awesome companies. We will send the prize winners an email with the pertinent information about their prizes soon.

Łukasz Kałużny

1 ebook from Manning (ARV $40.00)

Thomas Paetzold

1 ebook from Manning (ARV $40.00)

Lido Paglia

1 ebook from Manning (ARV $40.00)

Fabio Jr

1 ebook from Manning (ARV $40.00)

John OHarra

1 ebook from Manning (ARV $40.00)

Pete Maan

1  ebook from O’Reilly Media (ARV $20.00)

John Sneddon

1  ebook from O’Reilly Media (ARV $20.00)

Nuno Mota

1  ebook from O’Reilly Media (ARV $20.00)

James Berkenbile

1  ebook from O’Reilly Media (ARV $20.00)

Adam Funck

1  ebook from O’Reilly Media (ARV $20.00)

Matthew BETTON

1 each Amazon Gift ecard from BeyondTrust (ARV $50.00)

Ifiok Moses

1 copy PowerShell Plus Professional Edition version 4.0 from Idera (ARV $199)

BigTeddy

1 copy PrimalForms 2011 from SAPIEN Technologies (ARV $299)

2012 Scripting Games badge

2012 Scripting Games Judging Deadline extended

$
0
0
Summary: The deadline for grading submissions to the 2012 Scripting Games is extended Due to overwhelming level of participation, the deadline for judges to complete grading scripts submitted to the 2012 Scripting Games is extended to April 30, 2012 at...(read more)

Expert Commentary: 2012 Scripting Games Advanced Event 5

$
0
0

Summary: Microsoft MVP, Richard Siddaway, provides expert commentary for 2012 Scripting Games Advanced Event 5.

Microsoft Scripting Guy, Ed Wilson, is here. Richard Siddaway is the expert commentator for Advanced Event 5.

Photo of Richard Siddaway

Richard has been working with Microsoft technologies for over 22 years, and he spent time in most IT roles including analyst-programmer, server administration, support, DBA and architect. He has been interested in automation techniques (including automating job creation and submission on mainframes many years ago!). He has used VBScript and WMI since it became available on NT 4. Windows PowerShell caught his interest when he first heard about it  and he has been using it since the early beta versions.

He founded and runs the UK PowerShell User Group, and he is a Windows PowerShell MVP. He has given numerous talks about Windows PowerShell at various events in the UK, Europe, and the USA. He is a frequent speaker for Windows PowerShell user groups worldwide. He has a number of articles published about Windows PowerShell, including expert commentary’s on the Microsoft Scripting Games for which he has been a judge for the last two years. Windows PowerShell in Practice (Manning) was published in June 2010 and he is currently finishing PowerShell and WMI (Manning) to be published in 2012. Another book about Windows PowerShell 3.0 will be published towards the end of 2012. 

Blogs:
Richard Siddaway's Blog: Of PowerShell and Other Things 
PowerShell for Windows Admins
IT Knowledge Exchange: Get Answers from Your Peers

I’m going to approach this as I would when producing a production script. The starting point is the requirements that we get from the event scenario.

Requirements

You are an analyst on the server team of a medium sized organization. You are studying the performance and reliability of various servers on the network and decide to produce a report that lists the number of errors from all the traditional logs on a particular server. The code you use should be capable of running against a local computer, or against an arbitrary number of remote computers.

Other requirements:

  • You will use impersonation for all remote connections, so you do not need to be able to supply credentials.
  • You should not display errors due to permissions or due to no events matching your filter.
  • You should not make changes to the users’ environment. If you do, you should change them back at the end of the script. Modification to the users’ environment following script completion will cost you points.
  • Your script should run without prompting against the local computer.
  • Your output should be organized such that the largest source of errors appears at the top of the output.

Design

When I start to design a script I note all of the features, issues and constraints I have to consider to fulfil the requirements. The parts in italics are the features I will build into the script.

My design notes:

  • Needs to run in Windows PowerShell 2.0 and 3.0. Therefore, use  #Requires –version 2 to set a minimum Windows PowerShell version for running the script.
  • Only working with traditional logs. Can use Get-EventLog. WMI is alternative, but it’s a bit more complicated.
  • Use an ErrorAction of SilentlyContinue to avoid displaying unnecessary error messages when accessing logs.
  • Remote Registry Service must be running on the remote machine. Need to be able to start it, save state, and reset at end of script.
  • Have to assume DCOM is available on the remote machine and that the firewall is configured to allow traffic. Could work round that by using CIM cmdlets in Windows PowerShell 3.0 in place of WMI and/or WSMAN cmdlets to read the event logs. Still a problem with starting remote registry service.
  • Won’t assume the Windows PowerShell remoting is available. It would make the answer much easier to write. In a production environment, could probably get remoting enabled as a default.
  • Must work remotely on multiple machines. Get-EventLog has –Computername parameter.
  • Output to include log name and number of events in Error category. Make Error default, but allow for other types. Use ValidateSet attribute on parameter.
  • Should include computer name in output. Use New-Object and set a custom type name.
  • Output object but think of how to use it for well formatted report. Show examples in Help by using Format-Table –GroupBy.
  • Test connectivity to remote machine, and provide warning if can’t reach it. Use Quiet mode on Test-Connection.
  • Provide a default computer name. LocalHost doesn’t work with Get-EventLog, so need to test and modify.
  • Sort BEFORE output so largest output first.
  • Work on pipeline, accept single or no computer or an array of computer names.
  • Need to add Help. Use comment-based Help.
  • Create as an Advanced Function so can use in a future module. Should always consider how to use scripts.
  • Use Write-Verbose and Write-Debug to comment.

The full script is shown at the end of the post, but I’ll discuss the major design points here.

The best place to check that you are running with elevated privileges is at the beginning of processing. Advanced functions have a BEGIN, PROCESS, and END blocks. The BEGIN block runs when the first object in the pipeline hits the function; PROCESS runs for every object, and END runs after the last object has been processed. Putting the privileges check in the BEGIN block means that we only do it once.

The ForEach ($computer in $computername ){…} block that starts the PROCESS block ensures that every computer is processed if we pass multiple computers to the ComputerName parameter.

I find that testing if a machine can be pinged is useful because it enables the machine to be skipped gracefully. If you want to test if it’s there, use the Count parameter set to 1. One answer is just as good as four in this case.

The Remote Registry service state is saved in a variable so that it can be used to set the service back to its original state. I need to use WMI to discover the service start mode, but that’s a Read-only property as far as WMI is concerned, so I need to use Set-Service to perform the modifications.

Getting a list of event logs on the remote machine and skipping those that are empty will speed processing. I always use Measure-Object to count things for me—it’s there, and I don’t need to worry about possible syntax issues.

I’m outputting objects, but I have sorted them for a given machine in descending order. If you are working with multiple machines using the GroupBy parameter with Format-Table gives a good display.

"dc02", "webr201", "server02" |

Get-EventEntryCount |

Format-Table -Property Logname, EntryType,

EntryCount -GroupBy ComputerName -AutoSize

The results are shown in the image that follows. Pipe it into a file and you have a report fit for any manager. I’ve added comment-based Help to the function. I always put my Help at the end of the function. It’s a personal preference because I prefer to go straight to the code.

Image of command output

What else could we do to this function?

  • Allow multiple entry types, such as Error and Warning
  • Use remoting (but would need to know or test that it is configured)
  • Run as a background job
  • Use  workflows in PowerShell 3.0

Tips

Here are some of things that I discovered, or tripped over, or that are just plain useful:

  • Use Write-Verbose and Write-Debug as comments in addition to supplying additional information when called.
  • Remote Registry service must be running to access log information on a remote machine.
  • Remember to use the ComputerName parameter when you want to access logs on remote machines

Working with event logs is explained in more detail in my books, PowerShell in Practice and PowerShell and WMI.

The Script

Here is the final script:

#Requires -Version 2

function Get-EventEntryCount{

[CmdletBinding()]

param (

 [parameter(Position=0,

   ValueFromPipeline=$true,

   ValueFromPipelineByPropertyName=$true)]

 [Alias("CN", "Computer")] 

 [string[]]$computername="$env:COMPUTERNAME",

 

 [parameter(Position=1)]

 [ValidateSet("Error", "Information", "FailureAudit", "SuccessAudit", "Warning", "All", "*")]

 [string]$eventtype="Error"

)

BEGIN{

  $currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()

  $testadmin = (New-Object Security.Principal.WindowsPrincipal $currentUser).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)

  if (!$testadmin){

   Throw "Must be run with elevated privileges"

  }

}#begin

PROCESS{

  foreach ($computer in $computername ){

    switch ($computer) {

     "."         {$computer="$env:COMPUTERNAME"}

     "localhost" {$computer="$env:COMPUTERNAME"}

    }

 

    Write-Verbose "Processing computer: $computer"

   

    $data = @()

    if (Test-Connection -ComputerName $computer -Count 1 -Quiet){

 

    Write-Verbose "Starting Remote Registry service on $computer"

    $origrrsrv = Get-WmiObject -Class Win32_Service -Filter "Name='RemoteRegistry'" `

    -ComputerName $computer

 

    if ($origrrsrv.StartMode -eq "Disabled") {

      Set-Service -Name RemoteRegistry -ComputerName $computer -StartupType "Manual"

    }

 

    if ($origrrsrv.State -ne "Running") {

      $origrrsrv.StartService() | Out-Null

    }

 

    Write-Verbose "Retrieving logs for $computer"

     

    Get-EventLog -List -ComputerName $computer |

    foreach {

      Write-Verbose "Processing log: $($_.Log)"

       

      $logcount = New-Object -TypeName PSObject -Property @{

         ComputerName = $computer

         LogName = $($_.Log)

         EntryType = $eventtype

         EntryCount = 0

       }

       $logcount.PSTypeNames[0] = "LogEntryCount"

       

       if ($eventtype -eq "All" -or $eventtype -eq "*") {

         Write-Debug "Processing all entries"

         

         $logcount = $_.Entries.Count

       }

       elseif ($_.Entries.Count -gt 0) {

         Write-Debug "Processing event type $eventtype"

         

         $n = Get-EventLog -LogName $($_.Log) -EntryType $eventtype -ComputerName $computer `

       -ErrorAction SilentlyContinue

         

         if ($n -ne $null){

           Write-Debug "Entries found"

           $logcount.EntryCount =  $n | Measure-Object | select -ExpandProperty Count

         }

       }  # end if entries

       else {

         Write-Verbose "$($computer): $($_.Log) is empty"

       }

        $data += $logcount

 

        if ($origrrsrv.State -eq "Stopped") {

          $origrrsrv.StopService() | Out-Null

        }

 

        if ($origrrsrv.StartMode -eq "Disabled") {

          Set-Service -Name RemoteRegistry -ComputerName $computer -StartupType "Disabled"

        }

 

     } # end of log processing foreach

   }

   else {

     Write-Warning "Cannot contact $computer"

   } # end if ping

   Write-Output $data | sort EntryCount -Descending

 } ## end computer foreach

}#process

END{}#end

 

<#

.SYNOPSIS

Counts the number of entries of a given type

in the event logs of a system

 

.DESCRIPTION

One or more computers - from pipeline or parameter -  are

accessed to read the envent logs and count the entries of a

given type. Empty logs are tested and the count is set to zero

 

.PARAMETER  computername

Name of computer for which log information

is to be retrieved

 

.PARAMETER  eventtype

Log entry type to count.

Accepted values are -

"Error", "Information", "FailureAudit",

"SuccessAudit", "Warning", "All", "*"

 

.EXAMPLE

Get-EventEntryCount

 

Accesses logs on local machine. Peforms default display

 

.EXAMPLE

Get-EventEntryCount -computername "." |

Format-Table LogName, EntryCount -GroupBy ComputerName -AutoSize

 

Accesses logs on local machine. Format display and group by computer

 

.EXAMPLE

"dc02", "webr201", "server02" |

Get-EventEntryCount |

Format-Table -Property Logname, EntryType,

EntryCount -GroupBy ComputerName -AutoSize

 

Accesses logs on remote machines. Computer names accepted from pipeline.

Format display and group by computer

 

.EXAMPLE

Get-EventEntryCount -computername "dc02", "webr201", "server02" |

Format-Table -Property Logname, EntryType, EntryCount -GroupBy ComputerName -AutoSize

 

Accesses logs on remote machines. Computer names accepted as array.

Format display and group by computer

 

.INPUTS

Computer name - string or string array

Envent type - string. Must be member of set

 

.OUTPUTS

Returns a LogEntryCount custom object with

properties:

ComputerName - name of computer

LogName - name of log

EntryType - Type of log entry

EntryCount - count of entries

 

.NOTES

 

 

.LINK

 

#>

 

}

~Richard

2012 Scripting Games Guest Commentator Week Part 2 will continue Monday when we will present the scenario for Event 6. Join me tomorrow for a wrap-up blog about the 2012 Scripting Games.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Expert Commentary: 2012 Scripting Games Beginner Event 5

$
0
0

Summary: Windows PowerShell MVP, Jeffery Hicks, provides expert commentary for 2012 Scripting Games Beginner Event 5.

Microsoft Scripting Guy, Ed Wilson, is here. Jeffery Hicks is the expert commentator for Beginner Event 5.

Photo of Jeffrey Hicks

Jeffery is a Microsoft MVP in Windows PowerShell, Microsoft Certified Trainer, and an IT veteran with 20 years of experience—much of it spent as an IT consultant specializing in Microsoft server technologies. He works today as an independent author, trainer, and consultant. Jeff writes the popular Prof. PowerShell column for MPCMag.com, and he is a regular contributor to SMB IT Simplified and the Petri IT Knowledgebase. Jeff is a regular speaker at conferences, such as TechEd, and he often speaks about Windows PowerShell, Active Directory, Group Policy, and anything else than can make IT Pros more efficient and productive.

Your task is to write a Windows PowerShell command or tool that can query the application log on a computer and show how many events are associated with each event log source. Your first step would be to use the Get-EventLog cmdlet.

To use this cmdlet you can specify an event log (in this case, Application) and a computer name. Running this cmdlet could return a lot of entries, so to test your work as you develop it, I suggest using the –Newest parameter to only get a subset of entries. You might start like this:

PS C:\> Get-Eventlog –logname Application –computername $env:computername –newest 50

I like using the environmental variable for the computer name because it resolves to a “real” name rather than to LocalHost. When I have the command working, all that needs to be done is to insert a remote computer name. The output of the ComputerName cmdlet is a collection of event log entries.

What we are after is a way to group entries by the Source property. In other words, create a bucket for each Source value and put each matching entry in that bucket. Think about what is being asked? You need to group entries, so ask Windows PowerShell what you should use as follows:

PS C:\> help group

You should see the Group-Object cmdlet. After you read the Help and look at examples, hopefully you realize that you can pipe the event entries to Group-Object and specify the property to group on (in this case, Source). One quick tip though: Don’t assume that the table headings you see from cmdlet output are the actual property names. There are a number of cmdlets that use custom headings. The only way to learn the actual property name is to pipe the object to Get-Member. If you piped the Get-EventLog cmdlet to Get-Member, you would see that, in this case, the property is the same as the default output. Let’s group:

PS C:\> Get-Eventlog –logname Application –computername $env:computername –newest 50 | Group-Object –property Source

Group-Object writes a different object to the pipeline. Rerun the command and pipe it to Get-Member to see. To make it easier to read, we can sort on the Count property as follows:

PS C:\> get-eventlog -LogName Application -ComputerName $env:computername –newest 50 | Group-Object -property Source | Sort-property  Count -descending

The manager wants a simple list, so we can limit the display by selecting the Group-Object properties that we need:

PS C:\> get-eventlog -LogName Application -ComputerName $env:computername –Newest 50| Group-Object -property Source | Sort-property  Count -descending | Select Count,Name

The result isn’t necessarily formatted that nicely, but we can fix that. In fact, at this point, we can get all the application event log entries as shown here:

PS C:\> get-eventlog -LogName Application -ComputerName $env:computername | Group-Object -property Source | Sort-property  Count -descending | Select Count,Name | format-Table-autosize

You could send this to Out-File—or you could drop the Format-Table if you wanted to export to a CSV or do anything else with it. Finally, since we are doing this interactively, we can also take advantage of aliases and positional parameters to simplify the typing.

PS C:\>get-eventlog application –computer $env:computername | Group Source | Sort Count –desc | Select Count,Name | ft –auto

When faced with a task like, this start small and test each portion of the pipelined expression. Don’t try to write it all in one go. But when you have this worked out, you can easily turn it into a simple script so you don’t have to type all of this. Here’s my simple script that uses parameters with some default values. Because I only have to write this once, I’m using full cmdlet and parameter names.

#requires –version 2.0

Param ([string]$Logfile="Application",
[string]$Computername=$env:computername)

Write-Host "Getting logs from $logfile on $computername" –foregroundcolor Cyan

get-eventlog –Logname application –computername $env:computername |
Group-object -property Source | Sort-object -property Count –descending |
Select-Object -property Count,Name

I can run the script with default values or specify a computer name. The one addition I made was to add a Write-Host line to indicate what the script is doing because it might take a few minutes to query all the logs. I always use a color with Write-Host so I can tell what is console output and what is pipelined output.

Image of command output

If I wanted to format the results and save to a text file, because the script writes to the pipeline, all I need is an expression like this:

PS S:\> .\Beg5_2012.ps1 | format-table -autosize | out-file c:\work\applog.txt

Think about what you are trying to do, and seek Help in Windows  PowerShell. Then when scripting, always think about writing objects to the pipeline and leave formatting out of the script so you have maximum flexibility.

~Jeffrey

2012 Scripting Games Guest Commentator Week Part 2 will continue Monday when we will present the scenario for Event 6. Join me tomorrow for a wrap-up blog about the 2012 Scripting Games.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Beginner Leaderboard of the 2012 Scripting Games After 10 Days

$
0
0

This is the Beginner leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day, as event submissions are graded by the judges. All entries will continue to be graded by judges until 12:01 A.M. Pacific Time (UTC-8) on April 23, 2012. At that time, no more scripts will be evaluated, and the leaderboard will be finalized.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Beginner Events

User Name

Total Points

Scripts Rated

Total Ratings

Lido Paglia

48.25

10

22

Sahal Omer

47.17

10

22

Mike F Robbins

46.45

10

31

Dawn Villejoin

46.23

10

31

arnold moreno

44.87

10

22

Chris Manning @pbchris

44.33

10

23

Mr_Motown

44.17

10

25

yellowscope

44.17

10

25

JeffWouters

44.13

10

32

Matt benton

43.83

10

23

Cliff Harrison

43.75

10

24

wschoier

43.67

10

18

Srikanth

43.5

10

23

Eric Pankowski

43.5

10

23

Adam Funck

43.25

10

22

Andy Mello

43

10

22

Neil Clinch

42.75

9

18

Don Hunt

42.67

10

22

TechguyTJ

42.5

10

24

ScriptingWife

42.42

10

26

Paul Hiles

42.33

10

21

Grzegorz Kulikowski

42.33

10

21

Eleftheria Theologou

42.27

10

21

Charlie Jacobson

42

10

22

Daniel Killian

42

10

23

James McNeil

41.92

10

22

ckrull

41.92

10

26

qsilverx

41.9

10

24

Jordan Davis

41.83

10

23

Maciej

41.5

10

24

Chris-D

41.5

10

22

NCoppersmith

41.17

10

19

Nathan Mayberry

41.17

10

18

Duffman

41

10

26

GCaporale

41

10

26

mtb44

41

10

23

jaydee

41

10

20

David OBrien

41

10

19

Jhonny Yamaniha

40.92

10

23

Tim Muessig

40.92

10

24

Thiyagu

40.83

9

17

John OHarra

40.82

11

25

JoeTea

40.75

10

18

Marcin Pietras

40.67

9

15

James Berkenbile

40.67

10

22

Sigitas Grėbliūnas

40.5

9

17

David Waderich

40.33

10

20

Brian Bohanon

40.25

10

23

tyoung

40.25

10

25

Julie Andreacola

40.08

10

20

Alexis Ragual

40

9

19

Michael Moore

40

10

22

AballahSonDis

40

10

20

James White

40

10

25

NakiPS1

39.83

10

23

Steven Neel

39.67

9

17

John Grenfell

39.58

10

22

Vinay Bhandari

39.58

10

19

Werner

39.25

10

25

Tim Watson

39.2

10

23

Erica Miles

39.17

10

24

mark_@_li

39.17

10

18

Joshua Taylor

39.1

10

25

clbarnett

39

10

22

AmandaD

38.92

10

21

ngebhar2

38.83

10

22

BTmuney

38.83

10

25

Andy Bidlen

38.67

9

21

cemarsh06

38.67

10

23

John Russell

38.67

10

22

Fabio Jr

38.67

10

18

TSCSG

38.5

10

21

SM Yeoh

38.5

10

21

Chris Seiter

38.33

10

19

Brian Sabatini

38.33

10

23

Andrey Zvyagin

38.25

10

21

Shaun Watts

38.25

10

21

SLevenberg

38.17

10

19

Jeremy Cox

38.17

10

22

blahcubed

38

9

16

L4NM4N

38

10

23

Matt Tilford

38

10

23

MikeHowden

37.92

9

19

SdeDot

37.83

10

24

Steve Hall

37.83

10

20

James Stallwood

37.75

9

19

Pradeep Rawat

37.67

10

24

Lotte

37.67

10

22

rumart

37.5

10

23

Dominic Leonard

37.42

10

19

Jason Y.

37.33

10

22

Dexter Dhami

37.25

9

19

Derek Schauland

37.17

9

21

CraigJahnke

37.17

9

19

BradC

37.17

10

22

Ken Wilson

37.17

10

24

Xander Solis

37

10

25

Oleg Suchkov

36.9

10

21

Ifiok Moses

36.83

10

22

emekm

36.5

10

18

Wouter Beens

36.42

10

21

Daniel Thompson

36.33

10

22

Andreas Engkvist

36.33

10

23

Leon Nell

36.33

10

25

ICC_mworthley

36

10

25

Elmerp

35.83

10

17

Tyson J. Hayes

35.67

10

18

DaveyK

35.42

10

23

Robert B

35.17

10

22

dluke001

35.08

10

23

Jess Pomfret

35

10

22

Jon McCormick

34.92

10

24

Nadeem Vance

34.83

9

18

ICC_jruff

34.83

9

17

Phill McSherry

34.83

9

22

David Christian

34.83

10

21

ICC_RichardEisenberger

34.75

10

25

Nate Shepard

34.67

10

20

Riwe

34.67

10

22

Nathan Lare

34.5

9

17

Yves PASCAULT

34.5

10

19

AnotherPoShBlog

34.4

9

19

Max Schnell

34.33

8

15

Mads Hjort Larsen

34.33

10

21

eribaq

34.27

10

22

Daniel Dittenhafer

34

10

21

BreakDown

34

10

25

Mark P

33.92

8

19

Dave Maldonado

33.92

9

16

JeremyB

33.92

10

22

member2712

33.83

10

20

Roy M

33.67

9

18

therceg

33.67

9

16

Stephen Correia

33.67

10

19

John

33.6

9

18

Norman Manoh

33.5

10

19

ruskie

33.42

8

18

Nisha Sridhar

33.33

8

16

Timo Skupin

33.33

10

25

Rich Oswald

33.17

9

20

cphair

33

9

13

Will Nevis

32.75

10

22

NGelotte

32.67

7

15

Shevek

32.67

9

17

honeybadger

32.5

8

17

Marty

32.3

9

21

TheKidd

32

8

11

NSlearningPS

32

9

16

Daniel Snowden

31.92

9

17

DrLe

31.75

8

20

Zak Humphries

31.58

8

18

shiv

31.42

9

20

mand0

31.33

8

14

Zia

31.33

9

20

Mod10

31.33

10

25

Daniel Bicho

31.08

9

21

ResetSA

30.67

9

20

andre

30.5

8

18

The Awesome-Machine.NET

30.5

9

19

aaron d

30.5

10

20

Carl

30.42

8

22

mvanhorenbeeck

30.42

8

20

Geathan

30.37

9

19

MarkIsBack

30.17

8

18

Pendrag

30

8

13

Aaron Bednar

30

9

18

erunama

29.75

10

23

Vern Anderson

29.67

10

22

Matt Swint

29.58

8

20

nyoro2

29.5

7

14

Scott Baker

29.08

8

19

eklime

28.58

7

18

Clancy Wendt

28.33

9

20

jones89

28.17

9

21

Scott Alvarino

28

8

18

Brian Fraley

27.92

8

19

Dan

27.92

8

18

oki

27.5

8

14

MOW

27.5

8

17

W. Sterling

27.5

8

20

real fastcomputer

27.5

9

17

Andrew Morgan

27.42

7

18

Dennis James

27.33

7

13

Gica

27.15

7

18

Mouton

27.08

8

19

Matt McAllister

27

8

20

Stephen Brown

26.67

7

14

kloinerFeigling83

26.58

9

18

BernhardG

26.5

7

16

Sai Prasad Vaddepally

26.33

8

16

Clayton McKenzie

26.25

8

21

Joe Keohan

26

9

18

Chuck Lathrope

25.77

8

18

Japke

25.5

7

15

Sidewinder

25.5

7

18

Tony Rad

25.5

8

20

aalaminos

25.42

7

18

catremor

25.25

7

17

Steve Mahoney

24.75

8

18

something easier to read

24.58

7

18

BenJT

24.5

7

18

mnadobnik

24.25

7

15

mrgif1

24

6

10

Marcos Tsuda

23.92

8

14

Jason Omar

23.25

6

18

ICC_KFoley

23.17

7

20

Kryten-68

23

7

17

Emil Eriksson

23

7

15

Derrick Michelson

22.83

7

17

Mathieu Boulard

22.75

5

15

Kieran Walsh

22.67

7

14

octavmarius

22.17

5

12

toumi walid

22.17

7

19

EDW

22

7

13

robert broyles

21.83

7

13

Vinay Thakur

21.83

10

20

jarheadf23

21.75

6

13

Trevor Watkins

21.5

7

17

Shawn Melton

21.33

5

12

Chris Keim

21.33

6

15

Tony Uren

21

6

15

e46d8dd2e1625c7a6182b82bc012a7e0

20.5

8

19

Luke Forder

19.92

5

16

jbrek

19.83

6

14

Megha Kuruvilla

19.67

5

12

HitchHeik

19.17

6

16

Jeff Schulman

19

5

11

Mooseade

18.8

5

14

vNiklas

18.75

5

13

Shawn bequette

18.33

6

13

Daniel Headley

18.17

5

10

Shaun Gibbs

18

7

12

John van Leeuwen

17.58

6

14

Andrew Dauncey

17.33

5

10

Bastien B

16.5

5

16

Richard Holman

15.5

5

9

Mckie

15.47

6

14

Niel Fletcher

15

5

10

Colyn1337

14

3

4

ed3c64f9163ea026e949706ee53b2a34

14

5

9

lamaar75

13.33

5

13

Matt Vidrine

12

3

8

Chris Albert

11.33

3

6

Patrik Lindström

10.5

3

9

Bret Ridenour

10.5

4

12

Hov Arve

10.17

4

9

vbscripter

9

2

4

joeartz

9

2

6

Darren Maspero

9

2

8

Benduru

9

4

5

Peter Heydon

8.92

2

7

Tim Miller

8.67

3

11

Paul Sweeney

8.5

3

5

DWS

8.42

2

7

Dennis Jarjosa

8.42

2

7

plindgren

8.42

3

11

Yuri Kutovoy

8.42

3

11

Matt_A_

8.42

3

9

lvimeux

8.33

2

6

Jan R.

8.33

2

6

Arif Ali

8.33

3

10

Anders Wang

8.33

3

6

Jerame Caudill

8

2

6

Thomas Farmer

8

2

6

Andy Wyse

8

3

8

TomKupka

7.83

3

11

sfibich

7.75

2

7

Francisco Puig Diaz

7.75

3

11

Bryan

7.67

2

4

Mark Amann

7.67

2

6

Forrest Stanley

7.67

2

6

Name

7.6

3

10

Tomek A.

7.5

2

8

MarcoB78

7.42

2

7

TaylorGibb

7.4

2

8

Kevin

7.33

3

8

Michael Odermatt

7.08

2

7

Jeffrey Jacobs

7

2

6

Clinton Merritt

7

2

5

Greg Combs

7

3

7

Sander

6.83

2

7

Scott Button

6.83

2

7

Tom Parker

6.67

2

6

Coderaven

6.33

2

5

u2tb

6.33

2

6

Clayton Firth

6.25

2

7

Jeff Maes

6

2

6

Harshul

6

2

3

sebuko

5.75

2

6

greeme

5.67

2

6

Apnea

5.67

2

6

Satheesh

5.67

2

7

Timm Brochhaus

5.5

2

6

Jonny Earl Grey Lindbom

5.47

2

8

radek

5.42

2

7

Josh Nylander

5.42

2

7

TheZmann

5.33

2

4

Dave Baird

5.33

2

6

RJSN

5.33

2

4

DisplayName

5.33

2

5

Anthony Rum

5.25

2

7

Mike Lambert

5.25

2

7

foobar

5

1

1

Andrew Cameron

5

1

3

Dean Grant

5

1

3

Brian Wuchner

5

2

8

Joel Cook

5

2

6

JMARCH

5

2

2

Mallika Gogulamudi

5

2

8

acchong

4.75

1

4

Sudeep Bhaskar

4.5

1

4

Ken King

4.5

1

2

Petter Edin

4.33

2

6

Andrew Gardner

4.25

1

4

Jason Schmidtlein

4.25

1

4

Ryan Youngs

4

1

3

zacd

4

1

3

Claymonster

4

1

3

Filip Rejch

4

1

2

Francisco osorio

4

1

3

James B. Bizzell

4

1

2

Jay Lockard

4

1

3

evidence

4

1

3

Pavan Hotha

4

1

3

PSLearner

4

2

6

peter bishop

4

2

8

Björn

4

2

3

Dominic Daigle

3.85

2

9

Ola Skjeldal

3.67

1

3

Tim Hetzel

3.67

1

3

Brett Chandler

3.67

1

3

Chris Watson

3.67

2

5

Bob__Mule

3.5

1

4

Brendan Erofeev

3.5

1

4

sgatepunk

3.5

1

2

ocongil

3.33

1

3

Jasper van der Heijden

3.33

1

3

Tobias

3.33

1

3

70f53217af68ac357dfc1a46739257a6

3.33

1

3

MonitorMan

3.33

1

3

iTodd

3.33

1

3

Jonathan Birkett

3.33

1

3

redi311

3.33

1

3

Dexter

3.33

2

6

b4d93r

3.33

2

5

jeprus

3.25

1

4

skynetx

3

1

3

Crystal Diaz

3

1

3

Jude Croyle

3

1

3

Jakob Bindslet

3

1

3

Andrew Newman

3

1

3

mitch baker

3

1

3

miramar_unna

3

1

2

MrBatchFile

2.67

2

6

Jeremy Dunlop

2.33

1

3

a64c64bd8e1fe90b8b024ab272090e32

2.33

1

3

Daed

2.33

1

3

Jay mac

2.33

1

3

Byty

2

1

3

Nico

1.75

1

4

3166f9ba33499b4658123e7b0a84598f

1.67

1

3

Luca Christmann

1.67

1

3

le4ne

1.5

1

4

Sean Massey

1.33

1

3

David Granlund

1.33

1

3

Anjan Chidurala

1.33

1

3

Chris Nakagaki (Zsoldier)

1.33

1

3

2e638c99ea54b4ddb208033083f4ef24

1.33

1

3

Gabriel Tapia

1.33

1

3

j.vogt

1.33

1

3

TitleRequired

1.33

1

3

Jason Shaw

1.25

1

4

Eric Ray

1.25

1

4

Gary Jackson

1.25

1

4

gary gray

1.2

1

5

TechJLS3

1

1

5

WizardX

1

1

5

Jeremy Kieler

1

1

3

 


Advanced Leaderboard of the 2012 Scripting Games After 10 Days

$
0
0

This is the Advanced leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day, as event submissions are graded by the judges. All entries will continue to be graded by judges until 12:01 A.M. Pacific Time (UTC-8) on April 23, 2012. At that time, no more scripts will be evaluated, and the leaderboard will be finalized.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Advanced Events

User Name

Total Points

Scripts Rated

Total Ratings

Michał Gajda

31.67

7

15

Aleksey Shuvalov

31.33

7

16

Sergey Borisovich

29

7

13

Prosvetov Roman

28.83

7

12

gbdixg

28.67

7

10

Ryan Ries

28

7

12

John Sneddon

28

7

10

Mike Hammond

27.17

7

11

Jason Stangroome

25.67

6

12

Mikko

25.17

6

10

Thomas Paetzold

25

6

11

_Emin_

25

6

8

Ed Withers

25

6

11

KSchulte

24.83

6

12

Serkan Varoglu

24.67

6

9

Matthew Graeber

24.67

7

11

Scott1138

24.5

6

8

Nuno Mota

24.5

6

8

Serg

24.5

7

12

EasyMac308

23.75

6

11

Vladimir Stepic

23

6

8

Igway Jacobs

22.5

6

8

Frederick Duemig

22.5

6

8

Glenn Faustino

22.42

5

12

Francis D

22

5

7

ICC_RyanDennis

22

6

10

vNoob

22

7

12

Jeremy Caauwe

21.5

5

8

Ayo Wu

21.5

6

9

aml

21.17

6

10

Vincent Van Hecke

21

6

9

George Kesler

20.75

5

9

Grégory LUCAND

20.5

5

9

Matthew BETTON

20.5

6

8

Jack Chang

20.33

5

9

BigTeddy

20

5

10

Rob Campbell

19.33

5

9

Rohn Edwards

19

4

5

Robert Eder

19

5

8

Nathan Linley

19

6

10

Cameron Wilson

18.75

6

12

Albert Fortes

18.33

4

8

Kevin Hopcroft

17.67

4

7

Wes Stahler

17.5

4

5

SimonW

17.33

4

8

Jason Cole

17

4

6

Robert van den Nieuwendijk

17

4

5

Paulo J

16.83

5

9

Sergey Vorontsov

16.5

4

6

Kyle Neier

16

4

7

Joe D.

16

4

5

marcadamcarter

16

4

6

Stephanevg

16

4

6

Ryan C

16

4

8

Tomek Izydorczyk

15.83

4

8

Jeff Patton

15.75

4

10

sstranger

15.5

4

8

Joel Reed @J_lR_d {AZPOSH}

15.5

4

5

Matt Gohmann

15.5

4

6

Tom_G

15.5

4

7

Lars Seinwill

15.5

4

8

Łukasz Kałużny

15.5

4

6

Ken

15.5

4

5

Sean Brown Houses

15

4

5

Pete Maan

15

4

6

Daniel Cruz

15

4

6

Michael Moore

15

4

7

Pemo

15

5

7

Daniel Howe

14.5

4

5

Martijn Haverhoek

14

3

5

ICC_RDurkin

14

4

5

Rich Kusak

14

4

5

Kim Tram

14

4

5

Matthew Painter

13.5

3

5

Alex McFarland

13.5

4

6

ICC_JDyer

13.33

4

6

Trevor Hayman

13.17

4

7

Joshua Feierman

13

4

6

Ken Lin

13

4

6

Cesar Mendoza

12.83

4

7

Jaap Brasser

12.67

3

7

Tim Parkinson

12.5

3

4

Billy Angers

12.5

3

5

james seatter

12.5

4

9

AZPOSH - Brian T Young

12.5

4

5

Yves P

12.5

4

5

Jason Scott

12

3

4

DamienCharbonnel

12

4

6

Michael Topal

12

4

6

Tom Parker

11.83

3

6

Brian Wilhite

11.5

3

5

ScripterJT

11.5

3

6

Kirk Cessac

11

3

4

Franck RICHARD

11

3

5

UGSING_MattHitchcock

11

3

5

Brent Challis

11

3

5

Jason Hofferle

11

3

5

Schlauge

11

4

7

Paul Cunningham

10.67

3

6

Robert Mongold

10.5

3

5

Jesper Strandberg

10.5

3

4

MSFT-AutomationJason

10.5

3

4

Calle E

10.33

3

7

Sean Decker

10

3

5

Stijn Callebaut

10

4

5

Jason Wood

9.67

3

5

blindrood

9.5

3

6

Paul Iddon

9

2

3

J Skiba

8.5

2

3

resolver101

8.5

3

4

Internal_IT

8.5

3

5

Sam

8.5

3

4

DJ Grijalva

8

2

4

hemanth.damecharla

8

3

4

Brentos

8

3

4

Ken Hamilton

8

3

8

Kiss Tamás

7.67

2

5

Peter Heydon

7.5

2

4

Jason Lange

7.5

2

3

AaronHoover

7

2

3

Max Lindström

7

2

6

Dustin Hedges

7

3

4

PeetersOnlineNL

6.67

2

5

Carlos Nunez

6.67

2

5

Frank Peter Schultze

6.5

2

3

Brad Blaylock

6.5

2

4

Dave Ackroyd @LearnPowerShell

6

2

5

MattBoren

6

2

3

Clayton Firth

6

2

2

Patrik Lindström

5.67

2

6

Mr grnnnx

5.67

2

4

Jon Bryan

5.17

2

5

Dave Griffiths

5

1

2

Mark Weaver

5

1

2

Nico

5

1

1

mnadobnik

5

1

1

Yuri Kutovoy

5

2

6

Brian Carr

5

2

4

Dan Jakubczak

5

2

3

JeremiahC

5

2

3

f2b95d1a805fd4f8623b0d70b6ed3a19

4.67

2

5

Brandon Bettle

4.5

2

4

Damon Brinkley

4.5

2

4

Anonimista

4

1

2

jillwi

4

1

3

Anders Wang

4

1

1

T-Bone

4

1

2

Tobias

4

1

2

Jose Quinones

4

1

2

Claudiu P

4

1

2

smoshea

4

1

2

Scripting Scott Saari

4

1

2

Cameron Ove

4

1

2

Warpig

4

1

2

Justin Sowa

4

1

2

Jimmy Mac

4

1

1

Svartvoff

4

1

1

M Emek

4

1

1

Fredrik Wall

4

2

7

Justin Stokes

4

2

3

Clinton Merritt

3.67

1

3

Dan Richardson

3.67

1

3

Steelwing

3.67

1

3

MSFTW

3.67

1

3

herschelle

3.67

1

3

jeffrey yao

3.67

1

3

John Main

3.5

1

2

Yuriy Prikhodko

3.5

1

2

Ryan Schlagel

3.5

1

2

Brian Wuchner

3.5

1

2

Chris Oswalt

3.5

1

2

Wolfgang Kais

3.5

1

2

Tony McGee

3.5

1

2

Clint Bergman

3.5

1

2

PeterCS

3.5

1

2

Wayne Gault

3.5

1

2

Greg Martin

3.5

1

2

Chris Stewart

3.5

1

2

Oneill Cameron

3.5

1

2

SassDawe

3.5

1

2

Joshua Fuente

3.5

1

2

PatrikL

3.5

1

2

jessekozloski

3.5

1

2

IJuan

3.5

1

2

BurntChimney

3.5

1

2

Miruu

3.5

1

2

ThoamsBiebl

3.5

1

2

MarkJohnson

3.5

1

2

Patrick Dorsch

3.5

1

2

Ryan Shafer

3.5

1

2

Claus Søgaard

3.5

1

2

redi311

3.5

1

2

Josh

3.33

1

3

Kerry Boomsliter

3

1

1

Chris Brown

3

1

2

Jacques

3

1

2

Mike Lambert

3

1

2

kiran reddy

3

1

3

Dexter

3

1

2

crownedjitter

3

1

2

David Eilers

3

1

2

ofirey

3

1

2

Erin Huligan

3

1

2

Robert de Britto

3

1

2

Gregg Britton

3

1

2

Frank Migacz

3

1

2

Scripting Scott Saari

3

1

2

Matthew Vidrine

3

1

2

Tom Moser

3

1

2

Greg Shay

3

1

2

ginno

3

1

2

Jakob Bindslet

3

1

3

Zach M

3

1

2

Jiri Formacek

3

1

2

Jonny Earl Grey Lindbom

3

1

3

David Blackmore

3

2

3

Jason Milczek

3

2

3

dude9000

2.5

1

2

Dan Lepine

2.5

1

2

James Tryand

2.5

1

2

Claudio Westerik

2.5

1

2

Perry Harris

2.5

1

2

Chris Duck

2.5

1

2

Eddy Steenbergen

2.5

1

2

Nathan Cook - AU

2

1

2

Will Steele

2

1

4

Marcin Kowalczyk

2

1

2

Franck Malterre

2

1

2

skynetx

2

1

2

845ebf71ea404155b02971a5b6e8bc8d

2

1

2

WizardX2

2

1

2

Vivien Schlottmann

2

1

1

jcriswell

2

1

2

Luca Christmann

1.67

1

3

Rob Dowell

1.5

1

2

El Ryan

1.5

1

2

mand0

1.5

1

2

Filip Rejch

1.5

1

2

Daed

1.5

1

2

Andrew

1.5

1

2

Jim Vierra

1.33

1

3

oki

1

1

1

Brian T. Jackett

1

1

2

Joel Bennett ͦ᷈_ͦ᷉

1

1

1

Ákos Kinczel

1

1

2

Johan Åkerström

1

1

2

Hong

1

1

2

Jude Croyle

1

1

2

Paul Sweeney

1

1

1

Chris Nakagaki (Zsoldier)

1

1

2

Valeriy Aksyonov

1

1

2

Ken King

1

1

2

a690f3730d067a5c07abee279e6b0e97

1

1

1

 


Randomly Drawn Prize Winners: 2012 Scripting Games Day 10

$
0
0

This is the final random drawing for prizes. Thanks again to our wonderful sponsors for making these prizes possible. Please be sure to visit the sponsors page for more information about these awesome companies. The final leaderboards with our winners for the Beginner and Advanced Events will be posted on Tuesday May 1, 2012. Stay tuned…the competition is really heating up. Thank you for entering the 2012 Scripting GamesWe will send the prize winners an email with the pertinent information about their prizes soon. 


cphair

1  ebook from O’Reilly Media (ARV $20.00)

BradC

1  ebook from O’Reilly Media (ARV $20.00)

jeffrey yao

1  ebook from O’Reilly Media (ARV $20.00)

Joshua Feierman

1  ebook from O’Reilly Media (ARV $20.00)

Pemo

1  ebook from O’Reilly Media (ARV $20.00)

Francis D

1 ebook from Manning (ARV $40.00)

ICC_RyanDennis

1  ebook from Manning (ARV $40.00)

yellowscope

1  ebook from Manning (ARV $40.00)

Steve Hall

1  ebook from Manning (ARV $40.00)

Neil Clinch

1  ebook from Manning (ARV $40.00)

L4NM4N

1 each Amazon Gift ecard from BeyondTrust (ARV $50.00)

Serg

1 copy PrimalScript 2011 Studio from SAPIEN Technologies (ARV $599)

MarkIsBack

1 each PowerShell Video Library from Interface Technical Training (ARV $500)


2012 Scripting Games badge


When You Should Use PowerShell Aliases

$
0
0

Summary: Learn best practices for using the Windows PowerShell aliases at the command line and in scripts.

Microsoft Scripting Guy, Ed Wilson, is here. The 2012 Scripting Games are nearly over. The judges are all working, nearly around the clock, to get the final scripts graded so the final leaderboard will reveal this year’s top scripters. In a very real sense, everyone who participated is a winner because you have taken a positive step towards increasing your knowledge and understanding of a most exciting technology. One of my favorite tweets from this year’s games was one that said, “The Scripting Games is not a sprint, it is a marathon.” Just like marathon runners try to increase each year’s performance to achieve their personal best—so too is that the case with the Scripting Games.

Understanding aliases

Aliases are shortcuts to commands. One of the strengths of Windows PowerShell is that it is very readable code. For example, to get information about processes, the command is Get-Process. But this strength in readability is also a weakness, because it requires typing 11 characters just to get a list of processes. Of course, when compared to typing in dozens of lines of obscure VBScript code to perform the same task, 11 characters seems like a real bargain. But, people are always looking to do more with fewer resources, and scripting is no different. “Why do I have to type 11 characters to get a listing of processes when in (x, y, or z) shell I only need to type two letters to get the same information?” they may ask.

One way to address this is to use tab completion. By using tab completion, you only need to type Get-P and hit the Tab key once or twice until the command Get-Process appears, and then you hit ENTER to execute the command. By doing this, you are typing only five characters, and therefore, saving over 50% of the number of key strokes required to type Get-Process. The advantage of using tab completion is that you maintain readability and you reduce the number of key strokes required to type complete commands. To find aliases for the Get-Process cmdlet, use the Get-Alias cmdlet. This technique is shown here (remember that you can use tab expansion to type this command).

PS C:\> Get-Alias -Definition Get-Process

 

CommandType     Name                               Definition

-----------     ----                               ----------

Alias           gps                                Get-Process

Alias           ps                                 Get-Process

In fact, there is an alias for the Get-Alias cmdlet. To retrieve the alias use Get-Alias as shown here.

PS C:\> Get-Alias -Definition Get-Alias

CommandType     Name                               Definition

-----------     ----                               ----------

Alias           gal                                Get-Alias

When you use Get-Alias, you need to remember that it is used in different modes. With the first mode, the default is to resolve an alias to a Windows PowerShell command. Because the Name of the alias is the default parameter, you can use it as a positional parameter. I will talk about positional parameters later. For now, this means that you can use the gal alias for the Get-Alias cmdlet, and attempt to resolve the meaning of an alias named ps by typing the cryptic command that is shown here.

PS C:\> gal ps

CommandType     Name                               Definition

-----------     ----                               ----------

Alias           ps                                 Get-Process

Three main problems with aliases

There are essentially three problems when using aliases. The three problems are readability, understandability, and guarantee ability.

The problem of readability

Clearly, it is easier to read and to understand a command that looks like Get-Content than it is to understand a command that looks like gc. At times, it might be possible to figure out what an alias might mean by looking at it, but many times the alias might be a bit obscure. This is especially true when positional and partial parameters enter the picture. Is the following command good, bad, or indifferent?

gsv bits | spsv -wh

The problem of understandability

Because they are harder to understand, the use of aliases makes code more difficult to troubleshoot. It might take less time to type, but if the command does not work properly, it will take more time to troubleshoot simply because the code is more obscure. Typing a command, such as the one that is shown here, from the Windows PowerShell console is fairly easy to do, and it is great when it works. However, the code that appears is a bit difficult to understand for many people who use Windows PowerShell.

PS C:\> ls | ? {$_.psiscontainer} | % {"{0}`t{1}" -f $_.name,$_.lastaccesstime}

1       2/10/2012 10:43:41 PM

2012SG  2/9/2012 10:08:32 AM

data    12/6/2011 11:54:42 PM

driver  12/5/2011 9:21:14 PM

DRIVERS 12/12/2011 4:01:25 PM

fso     3/8/2012 6:38:12 PM

Intel   12/12/2011 4:07:56 PM

LogonLog        2/9/2012 4:30:18 PM

PerfLogs        7/13/2009 11:20:08 PM

Program Files   12/11/2011 1:35:38 PM

Program Files (x86)     2/20/2012 4:56:42 PM

SWTOOLS 12/11/2011 1:26:46 PM

Users   12/12/2011 4:09:22 PM

Windows 3/29/2012 11:26:51 AM

Now, what happens to the code when introducing an error into the mixture? Especially when the error does not display an error!

PS C:\> ls | ? {$_.pscontainer} | % {"{0}`t{1}" -f $_.name,$_.lastaccesstime}

PS C:\>

The longer version of the command is a bit easier to read. The code is still a bit convoluted, but at least you can start to get an idea about what the command is supposed to do.

Get-ChildItem | Where-Object {$_.psiscontainer} | ForEach-Object {"{0}`t{1}" -f $_.name,$_.lastaccesstime}

The problem of guarantee ability

Simply put, you can never be sure if an alias exists for a particular environment. There are three different types of aliases: compatibility, native, and custom. Compatibility aliases are aliases that make the transition from DOS to Windows PowerShell or from UNIX to Windows PowerShell easier. Aliases in this category include dir, ls, cat, type, and so forth. The compatibility aliases are not protected, and they are easily deleted at any time. To see all of the compatibility aliases, look for aliases that do not have the ReadOnly option set. The following command does just that.

Get-Alias | Where-Object { $_.options -notmatch 'readonly'}

The native aliases are aliases that are only meaningful within Windows PowerShell. You will not necessarily find a command in a UNIX or DOS environment that has the same command. These aliases have the ReadOnly option set. The following command displays all of the native aliases.

gal | ? { $_.options -match 'readonly'}

The thing is, read-only aliases are removable. To delete an alias, you use the Remove-Item cmdlet and choose the alias from the alias drive. A read-only alias generates an error unless you use the Force parameter. This technique is shown here.

PS C:\> Remove-Item alias:gc

Remove-Item : Alias was not removed because alias gc is constant or read-only.

At line:1 char:12

+ Remove-Item <<<<  alias:gc

    + CategoryInfo          : WriteError: (gc:String) [Remove-Item], SessionStateUn

   authorizedAccessException

    + FullyQualifiedErrorId : AliasNotRemovable,Microsoft.PowerShell.Commands.Remov

   eItemCommand

 

PS C:\> Remove-Item alias:gc -Force

PS C:\>

But deleting an alias from the alias drive does not remove it forever. It merely removes it from the current session. However, if you add the remove alias command to your Windows PowerShell profile, you effectively remove the alias forever. In fact, it is not uncommon to remove a canonical alias and to redefine the alias to something more useful. To do this, merely add the commands to your Windows PowerShell profile. Each time Windows PowerShell starts, it removes the offending alias and replaces it with your custom alias. Here is an example of changing GC from being an alias for Get-Content to being an alias for Get-Command.

Remove-Item alias:gc -force

Set-Alias -Name gc -Value Get-Command

Note   I am not advocating that you replace canonical aliases with your own custom aliases. I think that it could lead to unpredictable results—especially when you run code from other people who do, in fact, use aliases in their scripts. I am pointing out that such a situation is not unusual and that one must be careful when using aliases.

Best practices when working with aliases

First, if you completely control the environment and you never run code from outside your organization, then there is no problem using aliases. In fact, I know of some organizations that have a profile that defines organizational wide aliases. In addition, it is relatively easy to create a central Windows PowerShell profile so that no matter what machine you log on to, you will always have your aliases available. If this is the situation, and if the aliases utilized are clearly understood by everyone involved, go ahead and use aliases wherever you wish because you have mitigated all three of the problems mentioned earlier.

However, if you are sharing code outside your organization, or you are running code from outside your organization, it makes sense to mitigate the potential problem of aliases by not using them in scripts. Because Windows PowerShell is a scripting language and an interactive command shell, there are two best practices:

  • Use aliases when working interactively at the console
  • Don’t use aliases in scripts

Use aliases when working interactively at the console

When you are working interactively at the console, and as you learn new aliases, you can save yourself a considerable amount of time by using certain aliases. There are four one-letter aliases, and these are the least amount of typing possible. You should certainly add them to your repertoire. The following command displays these aliases.

PS C:\> Get-Alias ?

CommandType     Name                               Definition

-----------     ----                               ----------

Alias           %                                 ForEach-Object

Alias           ?                                  Where-Object

Alias           h                                  Get-History

Alias           r                                  Invoke-History

Don’t use aliases in scripts

If you are writing a script, you are creating an artifact that you will supposedly use again. Because it is more permanent, you should take a bit of extra time and resolve all aliases. In a script, you should not assume anything about the environment that will run the script. Of course, in real life, it is common to make all kinds of assumptions. Some of the more common assumptions are the version of the operating system and the requirement for administrative rights. Another big assumption, when a script accepts command-line parameters, is that the user will enter the correct type of information that the parameter requires.

Another common assumption is that an alias will be present when required. How does this happen? When developing and when testing the script, it is common to run the script on your own computer. But because the script works on your computer, does not mean that it will work on my computer. This is especially true when using aliases.

When you find an alias that you like, it is common to add that alias to your profile if it does not previously exist. Over time, you get used to using the alias until it becomes second nature. At that point, you may forget that it is a custom alias and expect it to exist everywhere. To avoid inadvertently introducing a user-defined alias into a production script, do not use any alias in the script. It is absolutely the safest approach. The added bonus is that your scripts will be easier to read and to understand. Consequently, the script will also be easier to troubleshoot, maintain, and modify in the future.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

The Problem with PowerShell Positional Parameters

$
0
0

Summary: In this blog, Microsoft Scripting Guy, Ed Wilson, talks about problems that can arise when using Windows PowerShell positional parameters.

Microsoft Scripting Guy, Ed Wilson, is here. Today is the final day of judging for the 2012 Scripting Games. The judges have made a magnificent effort these last few days to get the final scripts graded. The leaderboard has changed on a minute-by-minute basis for the last several days, and I know from twitter that many of you have been following the leaderboard more closely than University of Kentucky basketball fans followed the NCAA Final Four Tournament games.

In yesterday’s blog, When You Should Use PowerShell Aliases, I discussed the problems that indiscriminate alias usage creates.

One of the main problems with using Windows PowerShell aliases, even at the Windows PowerShell console, is that the code is much less readable. The same problem exists with positional parameters, parameter aliases, and partial parameters.

Understanding positional parameters

Positional parameters make Windows PowerShell commands shorter because you do not have to do as much typing, and some of the parameter names are rather long. But the problem is that unless you really know what a cmdlet does, and how it does it, you might not know what is actually going on. An example is the following command.

S C:\> copy c:\1 c:\3

So what does this command do? Well, it might copy the contents of the c:\3 folder to the c:\1 folder. Or it might copy the contents of the c:\1 folder to the c:\3 folder. For that matter, what is the copy command? The copy command is an alias for the Copy-Item cmdlet. Now, what is the first parameter? Is the parameter name source original, path, target, destination, or what? As a matter of fact, the first parameter is path. The second parameter is destination. To find this sort of information you need to use the Get-Help cmdlet with the Full switch. Each parameter entry includes information that states if the parameter is required, positional, or whatever. The following output displays the Path and the Destination parameter information.

-Path <string[]>

     Specifies the path to the items to copy.

 

     Required?                    true

     Position?                    1

     Default value

     Accept pipeline input?       true (ByValue, ByPropertyName)

     Accept wildcard characters?  False

-Destination <string>

    Specifies the path to the location where the items are to be copied.

 

    Required?                    false

    Position?                    2

    Default value

    Accept pipeline input?       true (ByPropertyName)

    Accept wildcard characters?  false

Understanding partial parameters

Another way of speeding up working with parameters is to use partial parameter names. For example, many cmdlets have a parameter named ComputerName. Now, this is a lot of typing. It is especially unfortunate because the Get-WmiObject cmdlet does not accept ComputerName positionally. Therefore, the following command fails.

PS C:\> gwmi win32_bios localhost

Get-WmiObject : Invalid query

At line:1 char:5

+ gwmi <<<<  win32_bios localhost

    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], ManagementExce

   ption

    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Comman

   ds.GetWmiObjectCommand

This does not mean that you are limited to typing the entire ComputerName parameter name each time you want to connect to a remote computer. You only need to type enough of the parameter so that it will distinguish it from other parameters that also start with the letter C. One easy way to see what will work is to simply run the command and look at the error message. In the following output, you can see that there are three parameters on the Get-WmiObject cmdlet that begin with the letter C. The first is Class, the second one is Credential, and the last parameter is ComputerName.

PS C:\> gwmi win32_bios -c localhost

Get-WmiObject : Parameter cannot be processed because the parameter name 'c' is ambi

guous. Possible matches include: -Class -Credential -ComputerName.

At line:1 char:5

+ gwmi <<<<  win32_bios -c localhost

    + CategoryInfo          : InvalidArgument: (:) [Get-WmiObject], ParameterBindin

   gException

    + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.GetW

   miObjectCommand

Based on the error message, you can safely use co as the partial parameter for ComputerName. This technique is shown here.

PS C:\> gwmi win32_bios -co localhost

SMBIOSBIOSVersion : 8BET47WW (1.27 )

Manufacturer      : LENOVO

Name              : Default System BIOS

SerialNumber      : R9FPY3P

Version           : LENOVO – 1270

Consider the following issues if you use partial parameter completion:

  • Partial parameters are hard to read and to understand. For example, the co that was discovered to work with the Get-WmiObject cmdlet does not look like ComputerName at all.
  • The same partial parameter does not always work in all cmdlets that may use that parameter. For example, there could be partial parameter conflicts in other cmdlets that would necessitate using Com or even Comp. Of course Comp begins to look a little more like ComputerName, and therefore, it begins to be more readable.
  • Partial parameters are not guaranteed to work the same way—even for the same cmdlets between versions. Because new parameters get added to existing cmdlets between versions, it can destroy previous working partial parameter names. This is not a compatibility issue because we do not guarantee that partial parameter names will ever work.

Because of the potential problems involved in working with partial parameters, it is general a good thing to avoid using them—even from the Windows PowerShell console line. Besides, when you have typed enough to make the partial parameter unique enough to use, a simple press of the Tab key completes the parameter anyway.

Understanding parameter aliases

Now we are back to the problem of aliases. However, there are a few caveats. The first is that in Windows PowerShell 2.0 parameter aliases are not documented. The way most people learn about parameter aliases is by looking at the code from someone who has learned about the parameter alias from someone else. In my Hey, Scripting Guy! Blog, Discovering PowerShell Cmdlet Parameter Aliases, I wrote some code that discovers parameter aliases and then writes the resulting aliases to a text file. The script takes a long time to run because there are many cmdlets, and many of these cmdlets have as many as 20 parameter aliases documented on them. Tab expansion does not help here, and Get-Help does not help either. The only way to find all of the parameter aliases is to read my blog—so I guess that means they are documented now.

The good thing about parameter aliases is that they are consistent among all cmdlets that use a particular parameter. Therefore, there is a parameter alias for ComputerName that is defined as cn. Anywhere you have ComputerName in a cmdlet, you can use cn instead. The advantage is that it is just as short as the co that we discovered would work for ComputerName, but with the advantage that cn actually makes sense.

Best practices around parameters

In a script, you should always use complete parameter names because with full parameter names, you actually know what the code is doing and it is more readable. You should avoid partial parameter names, and positional parameters for the same reason. Using the cn parameter alias is one that can safely be utilized because it makes sense, and it will be everywhere that the parameter itself resides. Because it cannot be deleted or overwritten (like cmdlet aliases can), the question of reliability does not come up.

When you are working interactively at the Windows PowerShell console, it is generally best to avoid positional parameters because they are very confusing, and it is easy to get them wrong. Is the target or the destination the first parameter? For simple cmdlets, such as Get-Process or Get-Service where the default parameter is Name, the positional use is fine, makes sense, and has little chance of error. The big problem with positional parameters comes into play where a cmdlet positionally accepts multiple parameters.

With partial parameters, the big problems are readability and the fact that they may not be consistent from version to version or even from cmdlet to cmdlet. Coupled with the fact that when you have a unique parameter, you can simply press the Tab key to avoid the problem altogether, partial parameters make little sense. If shortness of command is what you seek, you should find the parameter aliases and use them.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Expert Commentary: 2012 Scripting Games Advanced Event 6

$
0
0

Summary: Microsoft senior software engineer on the Windows PowerShell team, Lee Holmes, provides expert commentary for 2012 Scripting Games Advanced Event 6.

Microsoft Scripting Guy, Ed Wilson, is here. Lee Holmes is the expert commentator for Advanced Event 6.

Photo of Lee Holmes

Lee is a senior software engineer on the Microsoft Windows PowerShell team, and he has been an authoritative source of information about Windows PowerShell since its earliest betas. He is the author of the Windows PowerShell Cookbook, Windows PowerShell Pocket Reference, and the Windows PowerShell Quick Reference. 
 
Blog: Precision Computing 
Twitter: http://www.twitter.com/Lee_Holmes 
LinkedIn: http://www.linkedin.com/pub/lee-holmes/1/709/383

The script for the 2012 Scripting Games Advanced Event 6 is pretty descriptive, so rather than go over it again line-by-line, I thought it’d be helpful to talk about two of the main ideas that went into creating the script: jobs and streaming.

Networking is slow, parallel jobs are not

When running a large network-bound operation (such as retrieving the Win32_OperatingSystem class from a long list of computers), your computer spends the vast majority of its time waiting on the network: waiting for the connection, waiting for the computer to respond, and waiting for the data to get back.

To address this problem, Windows PowerShell 2.0 introduced the concept of “jobs”–primarily in remoting, WMI, and eventing. When you assign a multimachine task to a job, Windows PowerShell distributes your commands among many worker threads, which it then runs in parallel. Each worker thread processes one computer at a time. As each child job completes (for example, a remote WMI query against a specific computer), Windows PowerShell feeds that worker thread a command for another computer. By default, Windows PowerShell launches 32 child jobs in parallel.

What’s most amazing about Windows PowerShell jobs running 32 tasks in parallel is not that it makes things 32 times faster. It’s that it makes them even faster than that! The reason is a branch of computer science called “queueing theory.” Here’s a summary for the busy admin…

As a thought experiment, consider running a query against 92 computers one-by-one. Also, imagine that your first and second computers are rebooting, and they take a minute before failing to return their response. The other 90 return their responses in two seconds each.

The total time for that query is five minutes, for an average of about 3.3 seconds per successful computer. This is the same problem that happens when a bunch of hungry shoppers get stuck behind the crazy person paying with 100 coupons at the grocery store: every delay impacts everybody in line.

Now, consider the impact of parallel jobs in Windows PowerShell. Those first two rebooting computers use up two of our available worker threads for an entire minute, but we still have 30 more to process the remaining 90 computers. The total time for that query is about six seconds, giving an average time of about 0.07 seconds per successful computer. That’s 50 times faster than processing one computer at a time! Surprising, but incredibly cool. In the grocery store, this is like waiting in a single line, but having 32 cashiers serving from it.

Streaming is important

Given that this is likely to be a long-running script, you’re going to want to keep your results as dynamic as possible.

As the first step toward that, this script makes good use of the –Verbose and –Progress streams. As the script processes computers, it emits a progress message telling you which one it’s working on. If you specify the –Verbose parameter, you get even more detail—specifically, the uptime information as it writes it to the CSV.

This approach solves a common problem that I see: scripts that force their verbose or debugging information on the end user. The ultimate example of this sin is aggressive use of the Write-Host cmdlet. When you run this kind of script, you get reams and reams of text on screen, with no way to silence it. You can’t tell good information from bad, and other scripts can’t use it without this internal debugging information spewing all over the screen.

In addition to streaming progress, the script also streams its output. Although it would be easiest to collect all of the job output into a variable and then dump it to the CSV, all of your data is lost if you ever cancel the script while it is executing. When your script streams its output, you can easily monitor the results as they are received with this simple command:

Get-Content 20120409_Uptime.csv -Wait

If your query takes an hour to complete, it’s nice to be able to check its progress before then.

Jobs and streaming—two useful techniques to maximize the efficiency of long-running tasks. Now, here is my solution for Advanced Event 6:

##############################################################################

##

## Get-DistributedUptime

##

##############################################################################

 

<#

 

.SYNOPSIS

 

Retrieves the uptime information (as of 8:00 AM local time) for the list of

computers defined in the $computers variable. Output is stored in a

date-stamped CSV file in the "My Documents" folder, with a name ending in

"_Uptime.csv".

 

.EXAMPLE

 

Get-DistributedUptime

 

#>

 

param(

    ## Overwrites the output file, if it exists

    [Parameter()]

    [Switch] $Force

)

 

## Set up common configuration options and constants

$reportStart = Get-Date -Hour 8 -Minute 0 -Second 0

$outputPath = Join-Path ([Environment]::GetFolderPath("MyDocuments")) `

    ("{0:yyyyddMM}_Uptime.csv" -f $reportStart)

 

## See if the file exists. If it does (and the user has not specified -Force),

## then exit because the script has already been run today.

if(Test-Path $outputPath)

{

    if(-not $Force)

    {

        Write-Verbose "$outputPath already exists. Exiting"

        return

    }

    else

    {

        Remove-Item $outputPath

    }

}

 

## Get the list of computers. If desired, this list could be ready from

## a test file as well:

## $computers = Get-Content computers.txt

$computers = "EDLT1","EDLT2","EDLT3","EDLT4"

 

## Start the job to process all of the computers. This makes 32

## connections at a time, by default.

$j = Get-WmiObject Win32_OperatingSystem -ComputerName $computers -AsJob

 

## While the job is running, process its output

do

{

    ## Wait for some output, then retrieve the new output

    $output = @(Wait-Job $j | Receive-Job)

 

    foreach($result in $output)

    {

        ## We got a result, start processing it

        Write-Progress -Activity "Processing" -Status $result.PSComputerName

 

        ## Convert the DMTF date to a .NET Date

        $lastbootupTime = $result.ConvertToDateTime($result.LastBootUpTime)

 

        ## Subtract the time the report run started. If the system

        ## booted after the report started, ignore that for today.

        $uptimeUntilReportStart = $reportStart - $lastbootupTime

        if($uptimeUntilReportStart -lt 0)

        {

            $uptimeUntilReportStart = New-TimeSpan

        }

 

        ## Generate the output object that we're about to put

        ## into the CSV. Add a call to Select-Object at the end

        ## so that we can ensure the order.

        $outputObject = New-Object PSObject -Property @{

            ComputerName = $result.PSComputerName;

            Days = $uptimeUntilReportStart.Days;

            Hours = $uptimeUntilReportStart.Hours;

            Minutes = $uptimeUntilReportStart.Minutes;

            Seconds = $uptimeUntilReportStart.Seconds;

            Date = "{0:M/dd/yyyy}" -f $reportStart

        } | Select ComputerName, Days, Hours, Minutes, Seconds, Date

 

        Write-Verbose $outputObject

 

        ## Append it to the CSV. If the CSV doesn't exist, create it and

        ## PowerShell will create the header as well.

        if(-not (Test-Path $outputPath))

        {

            $outputObject | Export-Csv $outputPath -NoTypeInformation

        }

        else

        {

            ## Otherwise, just append the data to the file. Lines

            ## zero and one that we are skipping are the header

            ## and type information.

            ($outputObject | ConvertTo-Csv)[2]  >> $outputPath

        }

    }

} while($output)

~Lee

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 7.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

 

Expert Commentary: 2012 Scripting Games Beginner Event 6

$
0
0

Summary: Microsoft Windows PowerShell MVP, Sean Kearney, provides expert commentary for 2012 Scripting Games Beginner Event 6.

Microsoft Scripting Guy, Ed Wilson, is here. Sean Kearney is the expert commentator for Beginner Event 6.

Photo of Sean Kearney

Sean “The Kraken” Kearney is an infrastructure support analyst, Microsoft MVP in Windows PowerShell, and member of the Springboard Technical Experts Program. He is also one of this year’s first ever Honorary Scripting Guys and the mystery persona behind The BATCHman and Cmdlet. He is presently writing a book about Windows PowerShell.

He is so passionate about Windows PowerShell that he tried naming a pet gerbil “Cmdlet,” and then he attempted to use a Get-Wheel | Invoke-Run on it. We have been advised that he is also barred from any caffeinated beverages when he is presenting due to “The Edmonton Affair” at TechDays Canada.

You’re staring at the desk trying desperately to concentrate and force it to fold into the shape of an Armadillo, when the phone rings breaking your concentration…

“BARK!” a voice barks at you from the other end of the wire.  It’s the boss.

“I need to be able pull up metrics on our various servers and have to see how long any one of them has been running. Can you solve this for me? I’ve done some research, and I found that there is information in WMI that could help, but I’m not much of a programmer.”

You smile knowing this is a job Windows PowerShell can solve easily. “Sure! What do you have from WMI?”

“Well there’s a property called win32_operatingsystem that should have the time the computer started up, do you think you could calculate that against the current date somehow?”

“No problem sir….give me a few minutes, and I’ll create a simple script in Windows PowerShell to solve it all.”

You immediately head into the task by firing up Windows PowerShell to see what properties are available from win32_operatingsystem.

GET-WMIOBJECT win32_operatingsystem | GET-MEMBER

Drilling down the list you note that there is one called LastBootupTime. “Aha!  I’ll just pull up this property and subtract todays date!” you smile to yourself. Sometimes the boss IS right.

GET-WMIOBJECT win32_operatingsystem | SELECT-OBJECT –expandproperty LastBootupTime

But you stare at the screen with the results with a blank look.

20110201055602.000000-300

“Whaaaaaaa??????????????????!!!!!”

Your eyeballs pop out and roll on the desk. After you pick them up and put them back in your sockets, you take a second look and realize that you are looking at the date. It’s just in a different format. You decide to see if there might be some help from Get-Help about how to parse the date differently.

GET-HELP GET-DATE –examples

Drilling down near example #7, you notice a scenario that almost matches—manipulating the date from win32_bios. It appears that the WMI date is stored differently and there is an available method to convert it to a DotNet format.

You grab the object from win32_operatingsystem and store it away to mimic how the example presented it.

$A= GET-WMIOBJECT win32_operatingsystem

Using the example from Get-Help, you then try to convert the WMI object for LastBootupTime to a normal DotNet date.

$A.converttodatetime($A.LastBootupTime)

You blink and look at the screen in wonder and amazement.

Tuesday, February 01, 2011 5:56:02 AM

“Yes!” You nearly jump out of your shorts, knocking over the gerbil cage. “Now all I need to do is subtract this date from the current date and show the difference! Oh, I can’t wait to have this running on the servers!”

# Get name of local Server
$Machine=Hostname

# Get today’s date
$Today=GET-DATE

# Get the WMI object for the start time
$A=GET-WMIOBJECT win32_operatingsystem

# Obtain the Boot time in DOTNET format
$BootTime=$A.ConverttoDateTime($A.LastBootupTime)

# Calculate how many days the system has been up
$Uptime=$Today-$Boottime

# Obtain all the data for the output string
$Days=$Uptime.Days
$Hours=$Uptime.Hours
$Minutes=$Uptime.Minutes
$Seconds=$Uptime.Seconds
$JustDate=$Today.toshortdatestring()
$JustTime=$Today.toshorttimestring()

“The computer $Machine has been up for $Days days, $Hours hours, $Minutes minutes, $Seconds seconds, as of $JustDate $JustTime.”

You save the file as GETUPTIME.PS1 and hand it to the boss. He pops onto the security server to test it. He smiles.

“Great job! I knew investing in an IT Pro who knew Windows PowerShell would save me in the long term!  Thanks!” And he hands you keys to the most hallowed place in the office…

…the executive coffee room!

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 7.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Beginner Leaderboard for the 2012 Scripting Games as of April 23

$
0
0

This is the Beginner leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day as event submissions are graded by the judges. No more scripts are being accepted. Due to the large volume of submissions, the grading time has been extended for our busy judges.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Beginner Events

User Name

Total Points

Scripts Rated

Total Ratings

Lido Paglia

48.25

10

23

Sahal Omer

47.17

10

22

Mike F Robbins

46.45

10

31

Dawn Villejoin

46.23

10

31

arnold moreno

45.87

10

24

Chris Manning @pbchris

44.83

10

24

yellowscope

44.67

10

26

Mr_Motown

44.17

10

26

JeffWouters

44.13

10

32

Matt benton

43.83

10

23

Cliff Harrison

43.75

10

24

wschoier

43.67

10

20

Srikanth

43.5

10

25

Eric Pankowski

43.5

10

24

TechguyTJ

43.5

10

25

Adam Funck

43.25

10

22

Andy Mello

43

10

22

Neil Clinch

42.75

9

20

Don Hunt

42.67

10

23

Charlie Jacobson

42.5

10

24

Thiyagu

42.33

9

19

Paul Hiles

42.33

10

22

Grzegorz Kulikowski

42.33

10

21

Eleftheria Theologou

42.27

10

23

CraigJahnke

42.17

10

22

Daniel Killian

42

10

24

ckrull

41.92

10

26

James McNeil

41.92

10

23

qsilverx

41.9

10

24

Jordan Davis

41.83

10

24

ScriptingWife

41.58

10

28

Maciej

41.5

10

24

Chris-D

41.5

10

23

Jhonny Yamaniha

41.42

10

25

Brian Bohanon

41.25

10

24

JoeTea

41.25

10

20

NCoppersmith

41.17

10

21

David OBrien

41

10

22

jaydee

41

10

23

Duffman

41

10

27

GCaporale

41

10

27

mtb44

41

10

23

Tim Muessig

40.92

10

25

James Berkenbile

40.67

10

23

Julie Andreacola

40.58

10

22

Sigitas Grėbliūnas

40.5

9

19

James White

40.5

10

26

David Waderich

40.33

10

21

tyoung

40.25

10

25

Tim Watson

40.2

10

25

Vinay Bhandari

40.08

10

22

Alexis Ragual

40

9

19

AballahSonDis

40

10

21

Michael Moore

40

10

23

AmandaD

39.92

10

23

NakiPS1

39.83

10

24

Steven Neel

39.67

9

18

Nathan Mayberry

39.67

10

20

mark_@_li

39.67

10

20

John Grenfell

39.58

10

23

SM Yeoh

39.5

10

22

Werner

39.25

10

26

Marcin Pietras

39.17

9

18

John Russell

39.17

10

24

Erica Miles

39.17

10

24

Joshua Taylor

39.1

10

25

clbarnett

39

10

23

Mark P

38.92

9

23

ngebhar2

38.83

10

23

BTmuney

38.83

10

25

Andrey Zvyagin

38.75

10

23

Andy Bidlen

38.67

9

21

Rich Oswald

38.67

10

22

cemarsh06

38.67

10

23

SLevenberg

38.67

10

21

Matt Tilford

38.5

10

24

TSCSG

38.5

10

22

Chris Seiter

38.33

10

21

Brian Sabatini

38.33

10

23

Shaun Watts

38.25

10

22

Jeremy Cox

38.17

10

23

blahcubed

38

9

18

L4NM4N

38

10

23

MikeHowden

37.92

9

20

ICC_jruff

37.83

10

19

SdeDot

37.83

10

24

Steve Hall

37.83

10

21

James Stallwood

37.75

9

21

Pradeep Rawat

37.67

10

24

Lotte

37.67

10

23

Fabio Jr

37.67

10

21

rumart

37.5

10

24

Dominic Leonard

37.42

10

21

Jason Y.

37.33

10

23

Dexter Dhami

37.25

9

21

Derek Schauland

37.17

9

21

BradC

37.17

10

23

Ken Wilson

37.17

10

25

Xander Solis

37

10

25

Oleg Suchkov

36.9

10

22

Ifiok Moses

36.83

10

23

John OHarra

36.82

10

26

Robert B

36.67

10

23

emekm

36.5

10

20

Wouter Beens

36.42

10

21

Daniel Thompson

36.33

10

23

Leon Nell

36.33

10

25

Andreas Engkvist

36.33

10

23

Tyson J. Hayes

36.17

10

21

ICC_mworthley

36

10

25

NSlearningPS

36

10

19

Yves PASCAULT

36

10

21

DaveyK

35.92

10

24

Geathan

35.87

10

22

DrLe

35.75

9

22

NGelotte

35.67

8

17

ruskie

35.42

9

21

Elmerp

35.33

10

19

dluke001

35.08

10

23

Jess Pomfret

35

10

23

Jon McCormick

34.92

10

25

Nadeem Vance

34.83

9

20

Phill McSherry

34.83

9

22

David Christian

34.83

10

22

ICC_RichardEisenberger

34.75

10

25

Stephen Correia

34.67

10

21

Riwe

34.67

10

23

Nathan Lare

34.5

9

19

Dave Maldonado

34.42

9

18

AnotherPoShBlog

34.4

9

20

Max Schnell

34.33

8

16

member2712

34.33

10

22

eribaq

34.27

10

24

Roy M

34.17

9

20

BreakDown

34

10

26

Daniel Dittenhafer

34

10

22

JeremyB

33.92

10

23

Mads Hjort Larsen

33.83

10

22

therceg

33.67

9

18

John

33.6

9

20

Norman Manoh

33.5

10

21

Nisha Sridhar

33.33

8

16

Timo Skupin

33.33

10

25

Nate Shepard

33.17

10

21

cphair

33

9

16

Aaron Bednar

33

10

21

Will Nevis

32.75

10

23

Shevek

32.67

9

19

honeybadger

32.5

8

18

Marty

32.3

9

21

Daniel Snowden

31.92

9

20

Zak Humphries

31.58

8

19

TheKidd

31.5

8

14

shiv

31.42

9

21

mand0

31.33

8

16

Zia

31.33

9

21

Mod10

31.33

10

25

Daniel Bicho

31.08

9

23

MarkIsBack

30.67

8

19

ResetSA

30.67

9

20

andre

30.5

8

20

mvanhorenbeeck

30.42

8

21

Carl

30.42

8

23

aaron d

30

10

21

erunama

29.75

10

23

Vern Anderson

29.67

10

22

jones89

29.67

10

24

Matt Swint

29.58

8

20

nyoro2

29.5

7

15

Pendrag

29.5

8

15

mnadobnik

29.25

8

17

Scott Baker

29.08

8

20

The Awesome-Machine.NET

29

9

21

eklime

28.58

7

18

Clancy Wendt

28.33

9

21

Scott Alvarino

28

8

18

Brian Fraley

27.92

8

19

Dan

27.92

8

19

oki

27.5

8

14

MOW

27.5

8

17

W. Sterling

27.5

8

20

real fastcomputer

27.5

9

19

Andrew Morgan

27.42

7

18

Dennis James

27.33

7

14

Gica

27.15

7

19

Mouton

27.08

8

20

Matt McAllister

27

8

20

Stephen Brown

26.67

7

16

kloinerFeigling83

26.58

9

19

BernhardG

26.5

7

16

Sai Prasad Vaddepally

26.33

8

16

Clayton McKenzie

26.25

8

22

Chuck Lathrope

25.77

8

19

Japke

25.5

7

16

Sidewinder

25.5

7

18

Tony Rad

25.5

8

21

aalaminos

25.42

7

18

catremor

25.25

7

17

Joe Keohan

25

9

20

Steve Mahoney

24.75

8

18

something easier to read

24.58

7

18

BenJT

24.5

7

18

Marcos Tsuda

24.42

8

16

mrgif1

24

6

11

Jason Omar

23.25

6

18

ICC_KFoley

23.17

7

20

Kryten-68

23

7

18

Emil Eriksson

23

7

16

Derrick Michelson

22.83

7

17

Mathieu Boulard

22.75

5

15

Kieran Walsh

22.67

7

14

robert broyles

22.33

8

16

octavmarius

22.17

5

12

toumi walid

22.17

7

20

EDW

22

7

13

Vinay Thakur

21.83

10

22

jarheadf23

21.75

6

13

Trevor Watkins

21.5

7

17

Shawn Melton

21.33

5

13

Chris Keim

21.33

6

15

Tony Uren

21

6

15

e46d8dd2e1625c7a6182b82bc012a7e0

20.5

8

20

Luke Forder

19.92

5

16

Megha Kuruvilla

19.67

5

12

jbrek

19.33

6

15

HitchHeik

19.17

6

16

Jeff Schulman

19

5

12

Mooseade

18.8

5

14

vNiklas

18.75

5

13

Shawn bequette

18.33

6

14

Daniel Headley

18.17

5

10

Andrew Dauncey

17.83

5

11

John van Leeuwen

17.58

6

15

Niel Fletcher

17.5

6

12

Shaun Gibbs

17.5

7

13

Bastien B

16.5

5

16

Richard Holman

15.5

5

9

Mckie

15.47

6

15

Colyn1337

14

3

4

ed3c64f9163ea026e949706ee53b2a34

14

5

9

lamaar75

13.33

5

13

Matt Vidrine

12

3

8

Chris Albert

11.33

3

6

Patrik Lindström

10.5

3

9

Bret Ridenour

10.5

4

12

Paul Sweeney

10.5

4

8

Hov Arve

10.17

4

9

vbscripter

9

2

4

joeartz

9

2

6

Darren Maspero

9

2

8

Peter Heydon

8.92

2

7

Tim Miller

8.67

3

11

Benduru

8.5

4

7

Dennis Jarjosa

8.42

2

7

DWS

8.42

2

7

Yuri Kutovoy

8.42

3

11

Matt_A_

8.42

3

9

plindgren

8.42

3

11

lvimeux

8.33

2

6

Jan R.

8.33

2

6

Arif Ali

8.33

3

10

Anders Wang

8.33

3

6

Jerame Caudill

8

2

6

Thomas Farmer

8

2

6

Andy Wyse

8

3

9

TomKupka

7.83

3

11

sfibich

7.75

2

7

Francisco Puig Diaz

7.75

3

11

Bryan

7.67

2

4

Forrest Stanley

7.67

2

6

Mark Amann

7.67

2

6

Name

7.6

3

10

Tomek A.

7.5

2

8

MarcoB78

7.42

2

7

TaylorGibb

7.4

2

8

Kevin

7.33

3

8

Michael Odermatt

7.08

2

7

Jeffrey Jacobs

7

2

6

Greg Combs

7

3

7

Scott Button

6.83

2

7

Sander

6.83

2

7

Coderaven

6.33

2

5

u2tb

6.33

2

6

Jeff Maes

6

2

6

Harshul

6

2

3

sebuko

5.75

2

6

greeme

5.67

2

6

Apnea

5.67

2

6

Satheesh

5.67

2

7

Timm Brochhaus

5.5

2

6

Jonny Earl Grey Lindbom

5.47

2

8

radek

5.42

2

7

Josh Nylander

5.42

2

7

TheZmann

5.33

2

4

Dave Baird

5.33

2

6

RJSN

5.33

2

4

DisplayName

5.33

2

5

Anthony Rum

5.25

2

7

Mike Lambert

5.25

2

7

Andrew Cameron

5

1

3

foobar

5

1

2

Dean Grant

5

1

3

Brian Wuchner

5

2

8

Joel Cook

5

2

6

JMARCH

5

2

3

miramar_unna

5

2

4

Mallika Gogulamudi

5

2

8

acchong

4.75

1

4

Ken King

4.5

1

2

Sudeep Bhaskar

4.5

1

4

Petter Edin

4.33

2

6

Andrew Gardner

4.25

1

4

Jason Schmidtlein

4.25

1

4

Ryan Youngs

4

1

3

Pavan Hotha

4

1

3

zacd

4

1

3

Francisco osorio

4

1

3

Claymonster

4

1

3

Filip Rejch

4

1

2

James B. Bizzell

4

1

2

Jay Lockard

4

1

3

evidence

4

1

3

PSLearner

4

2

6

peter bishop

4

2

8

Björn

4

2

3

Dominic Daigle

3.85

2

9

Ola Skjeldal

3.67

1

3

Brett Chandler

3.67

1

3

Tim Hetzel

3.67

1

3

Chris Watson

3.67

2

5

Bob__Mule

3.5

1

4

Brendan Erofeev

3.5

1

4

sgatepunk

3.5

1

2

ocongil

3.33

1

3

Jasper van der Heijden

3.33

1

3

70f53217af68ac357dfc1a46739257a6

3.33

1

3

MonitorMan

3.33

1

3

iTodd

3.33

1

3

Jonathan Birkett

3.33

1

3

redi311

3.33

1

3

Dexter

3.33

2

6

b4d93r

3.33

2

5

jeprus

3.25

1

4

skynetx

3

1

3

Jude Croyle

3

1

3

Crystal Diaz

3

1

3

Andrew Newman

3

1

3

mitch baker

3

1

3

MrBatchFile

2.67

2

6

Jeremy Dunlop

2.33

1

3

a64c64bd8e1fe90b8b024ab272090e32

2.33

1

3

Daed

2.33

1

3

Jay mac

2.33

1

3

Byty

2

1

3

3166f9ba33499b4658123e7b0a84598f

1.67

1

3

Luca Christmann

1.67

1

3

le4ne

1.5

1

4

Sean Massey

1.33

1

3

David Granlund

1.33

1

3

Anjan Chidurala

1.33

1

3

2e638c99ea54b4ddb208033083f4ef24

1.33

1

3

Chris Nakagaki (Zsoldier)

1.33

1

3

Gabriel Tapia

1.33

1

3

j.vogt

1.33

1

3

TitleRequired

1.33

1

3

Eric Ray

1.25

1

4

Gary Jackson

1.25

1

4

Jason Shaw

1.25

1

4

gary gray

1.2

1

5

TechJLS3

1

1

5

WizardX

1

1

5

Jeremy Kieler

1

1

3

 

Advanced Leaderboard for the 2012 Scripting Games as of April 23

$
0
0

This is the Advanced leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day as event submissions are graded by the judges. No more scripts are being accepted. Due to the large volume of submissions, the grading time has been extended for our busy judges.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Beginner Events

User Name

Total Points

Scripts Rated

Total Ratings

Kevin Hopcroft

46.67

10

18

Michał Gajda

44.67

10

20

Albert Fortes

43.33

9

16

Francis D

40

9

16

Billy Angers

39.5

9

17

Mikko

39.17

9

15

Ed Withers

38

9

16

Sergey Borisovich

37.5

9

16

Prosvetov Roman

37.33

9

17

Rob Campbell

37.33

9

13

Matthew Painter

36.5

8

14

Kyle Neier

36.5

8

16

Nuno Mota

36.5

9

14

EasyMac308

36.25

9

17

Mike Hammond

36.17

9

15

gbdixg

35.67

9

16

Jeremy Caauwe

35.5

8

13

Scott1138

35.5

9

13

Glenn Faustino

35.42

8

18

Aleksey Shuvalov

35.33

8

17

Matthew Graeber

35.17

9

14

Brian Wilhite

35

8

17

Jason Hofferle

34.5

8

14

BigTeddy

34

8

15

Sean Brown Houses

33.83

8

15

KSchulte

33.83

8

14

Jason Stangroome

33.67

8

14

Sergey Vorontsov

33.5

8

11

Robert Mongold

33.5

8

10

Joel Reed @J_lR_d {AZPOSH}

33.5

8

10

Rohn Edwards

33

7

9

_Emin_

33

8

14

Pete Maan

33

8

10

ICC_RyanDennis

33

9

13

Lars Seinwill

32.5

8

12

AZPOSH - Brian T Young

32.5

8

11

Ryan Ries

32.5

8

16

John Sneddon

32.5

8

12

Łukasz Kałużny

32.5

8

10

Rich Kusak

32

8

10

Igway Jacobs

32

8

11

Serkan Varoglu

31.67

8

11

Vladimir Stepic

31

8

10

Frederick Duemig

31

8

11

aml

30.67

8

13

Tim Parkinson

30.5

7

8

Ken

30.5

7

8

Robert van den Nieuwendijk

30

7

8

Jaap Brasser

29.67

7

11

MSFT-AutomationJason

29.5

7

8

Matthew BETTON

29.5

8

12

Joshua Feierman

29

8

10

Robert Eder

29

8

11

Paulo J

28.83

8

12

Cesar Mendoza

28.83

8

11

Jason Wood

28.67

8

13

Matt Gohmann

28.5

7

9

Daniel Howe

28.5

7

8

Jesper Strandberg

28.5

7

8

Vincent Van Hecke

28.5

8

12

Serg

28.5

9

15

Kim Tram

28

7

8

Jason Cole

28

7

12

blindrood

28

7

11

Daniel Cruz

28

7

10

Stephanevg

28

7

9

Joe D.

28

7

8

Ryan C

28

8

12

Thomas Paetzold

28

8

13

vNoob

28

9

15

George Kesler

27.75

7

11

Alex McFarland

27.5

7

11

Cameron Wilson

27.25

8

15

Ayo Wu

26.5

7

10

Sam

26.5

7

8

ICC_JDyer

26.33

7

9

Schlauge

26

8

11

Ken Lin

26

8

10

Grégory LUCAND

25.5

8

13

Pemo

25

8

10

Yves P

24.5

7

8

Nathan Linley

23

7

11

DamienCharbonnel

23

7

9

SimonW

22.33

5

9

Jack Chang

20.33

5

9

Franck RICHARD

20

5

7

Ken Hamilton

20

6

11

ICC_RDurkin

19

6

7

sstranger

18.5

5

9

Wes Stahler

17.5

4

5

Jason Scott

17

4

8

hemanth.damecharla

17

6

7

marcadamcarter

16

4

6

Tomek Izydorczyk

15.83

4

8

Jeff Patton

15.75

4

10

Tom_G

15.5

4

7

Internal_IT

15.5

5

7

Michael Moore

15

4

7

Brentos

15

5

6

james seatter

14.5

5

10

Martijn Haverhoek

14

3

5

Mr grnnnx

13.67

4

6

Calle E

13.33

4

8

Trevor Hayman

13.17

4

8

jeffrey yao

12.67

3

5

Michael Topal

12

4

6

Tom Parker

11.83

3

7

ScripterJT

11.5

3

6

Kirk Cessac

11

3

4

UGSING_MattHitchcock

11

3

7

Brent Challis

11

3

5

Paul Cunningham

10.67

3

6

J Skiba

10.5

3

5

Sean Decker

10

3

5

Vivien Schlottmann

10

3

3

Dustin Hedges

10

4

5

Stijn Callebaut

10

4

5

T-Bone

9

2

3

jillwi

9

2

4

Paul Iddon

9

2

3

resolver101

8.5

3

4

DJ Grijalva

8

2

4

Kiss Tamás

7.67

2

5

Jason Lange

7.5

2

3

Max Lindström

7

2

6

AaronHoover

7

2

3

Carlos Nunez

6.67

2

5

PeetersOnlineNL

6.67

2

5

Frank Peter Schultze

6.5

2

3

Brad Blaylock

6.5

2

4

Dave Ackroyd @LearnPowerShell

6

2

5

Clayton Firth

6

2

2

MattBoren

6

2

3

Jon Bryan

5.17

2

5

Dave Griffiths

5

1

2

Mark Weaver

5

1

2

Nico

5

1

1

Max Schnell

5

1

1

Brian Carr

5

2

4

Dan Jakubczak

5

2

3

JeremiahC

5

2

3

f2b95d1a805fd4f8623b0d70b6ed3a19

4.67

2

5

Brandon Bettle

4.5

2

4

Damon Brinkley

4.5

2

4

Anonimista

4

1

2

BernhardG

4

1

1

Tobias

4

1

2

Cameron Ove

4

1

2

Jose Quinones

4

1

2

Claudiu P

4

1

2

smoshea

4

1

2

Scripting Scott Saari

4

1

2

Warpig

4

1

2

Justin Sowa

4

1

2

Svartvoff

4

1

1

M Emek

4

1

1

Jimmy Mac

4

1

1

Fredrik Wall

4

2

7

Justin Stokes

4

2

3

Clinton Merritt

3.67

1

3

Dan Richardson

3.67

1

3

Steelwing

3.67

1

3

MSFTW

3.67

1

3

herschelle

3.67

1

3

Ryan Schlagel

3.5

1

2

John Main

3.5

1

2

Yuriy Prikhodko

3.5

1

2

Chris Oswalt

3.5

1

2

Wolfgang Kais

3.5

1

2

PeterCS

3.5

1

2

Tony McGee

3.5

1

2

Clint Bergman

3.5

1

2

Wayne Gault

3.5

1

2

Greg Martin

3.5

1

2

IJuan

3.5

1

2

PatrikL

3.5

1

2

BurntChimney

3.5

1

2

jessekozloski

3.5

1

2

Claus Søgaard

3.5

1

2

Ryan Shafer

3.5

1

2

Chris Stewart

3.5

1

2

Oneill Cameron

3.5

1

2

SassDawe

3.5

1

2

Joshua Fuente

3.5

1

2

Miruu

3.5

1

2

ThoamsBiebl

3.5

1

2

MarkJohnson

3.5

1

2

Patrick Dorsch

3.5

1

2

artnib

3.5

1

2

Josh

3.33

1

3

Kerry Boomsliter

3

1

1

Jacques

3

1

2

kiran reddy

3

1

3

Chris Brown

3

1

2

David Eilers

3

1

2

crownedjitter

3

1

2

MsMiller

3

1

1

Matthew Vidrine

3

1

2

Tom Moser

3

1

2

Greg Shay

3

1

2

ginno

3

1

2

Robert de Britto

3

1

2

Gregg Britton

3

1

2

ofirey

3

1

2

Erin Huligan

3

1

2

Frank Migacz

3

1

2

Scripting Scott Saari

3

1

2

Jiri Formacek

3

1

2

Jakob Bindslet

3

1

3

Zach M

3

1

2

David Blackmore

3

2

3

Jason Milczek

3

2

3

Dan Lepine

2.5

1

2

James Tryand

2.5

1

2

dude9000

2.5

1

2

Chris Duck

2.5

1

2

Claudio Westerik

2.5

1

2

Perry Harris

2.5

1

2

Eddy Steenbergen

2.5

1

2

Will Steele

2

1

4

Nathan Cook - AU

2

1

2

Franck Malterre

2

1

2

Marcin Kowalczyk

2

1

2

845ebf71ea404155b02971a5b6e8bc8d

2

1

2

jcriswell

2

1

2

WizardX2

2

1

2

Rob Dowell

1.5

1

2

El Ryan

1.5

1

2

Andrew

1.5

1

2

Jim Vierra

1.33

1

3

Brian T. Jackett

1

1

2

Joel Bennett ͦ᷈_ͦ᷉

1

1

1

Ákos Kinczel

1

1

2

Johan Åkerström

1

1

2

Hong

1

1

2

Mathieu Boulard

1

1

1

Valeriy Aksyonov

1

1

2

a690f3730d067a5c07abee279e6b0e97

1

1

1

 

Expert Commentary: 2012 Scripting Games Advanced Event 7

$
0
0

Summary: Microsoft MVP, Tome Tanasovski, provides expert commentary for 2012 Scripting Games Advanced Event 7.

Microsoft Scripting Guy, Ed Wilson, is here. Tome Tanasovski is the expert commentator for Advanced Event 7.

Photo of Tome Tanasovski

Tome is a Windows engineer for a market-leading global financial services firm in New York City. He is the founder and leader of the New York City PowerShell User group, a blogger, and a regular contributor to the Official Scripting Guys Forum. In 2011, he became a cofounder of the NYC Techstravaganza, coauthored the Windows PowerShell Bible, and received the title of Honorary Scripting Guy from the Hey, Scripting Guy! Blog. Tome has also received the MVP award in Windows PowerShell from Microsoft for the last two years. 

A real scripting language can solve a problem in one line of code. That happens to be the case for this problem. Even after you’ve tackled each of the design points, you can still run the script as one line. So let’s start with the simple line that satisfies the problem and a couple of the design points. It uses Get-WinEvent to ensure that you are reading all of the logs that are available in Windows 7:

Get-WinEvent -ListLog * |?{$_.IsEnabled} |%{$_|Get-WinEvent -MaxEvents 1 -ErrorAction SilentlyContinue}

I should note that the question mark (?) and the percent sign (%) are aliases for Where-Object and Foreach-Object respectively. They are two of the most useful aliases when working in Windows PowerShell. However, in a contest like this, it’s best to avoid these aliases. Unlike Select, Where, ForEach, and Sort, the question mark and percent sign are frowned upon by some judges. My final solution does not use these shortcuts, but for the purpose of a one-liner they are always acceptable.

The first thing you may notice when running the previous script is that it may still give you errors—even though you set the ErrorAction parameter to SilentlyContinue. Get-WinEvent will choke on certain logs, if you are not running Windows PowerShell with elevated privileges through UAC (run as Adminstrator). Although it’s not a design requirement, I added the following to my script to ensure that an operator is running my script with enough privilege to ensure that they can hit every log:

$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()

$principal = New-Object System.Security.Principal.WindowsPrincipal($id)

if ($principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {

            # Script

} else {

  Write-Error "PowerShell is not running elevated. This script requires elevated Administrator privileges in order to run"

}

One of the design points for this event is, “Your code should query hidden logs if they are enabled and they contain at least one entry.”

If you’re not familiar with the hidden analytic and debug logs that exist in Windows 7, you can find them in Event Viewer by clicking View, and then selecting Show Analytic and Debug Logs.

Image of menu

When these logs are visible, they can be enabled by right-clicking a log and viewing the properties of the log.

Image of menu

To view the logs that are available on a system through Windows PowerShell, regardless of whether they are hidden, you must use the Force parameter when using Get-WinEvent with the ListLog parameter.

Get-WinEvent -ListLog * -Force

If you only want to view enabled logs, you need to filter the logs that have the IsEnabled property set to True.

Get-WinEvent -ListLog * -Force |where {$_.IsEnabled}

To check that the log has at least one record, you can inspect the RecordCount property. The problem with RecordCount is that it won’t display the number of records for the hidden logs that are analytic or debug logs. Due to the nature of how these logs are written, you do not have the same type of insight into the log as you do with the others.

For the same reason, you must use the Oldest parameter switch with Get-WinEvent to view these logs. This switch returns the logs in reverse order. The side effect is that if you use the MaxEvents parameter of Get-WinEvent, it will return the first event instead of the last one. This leads to the following line of code that must be used with analytic and debug logs to get the most recent event:

'LogName' |Get-WinEvent -Oldest -ErrorVariable e -ErrorAction SilentlyContinue |select -First 1

You’ll note that I’m using SilentlyContinue with ErrorVariable here. Unfortunately, Get-WinEvent does not throw an exception, so you cannot use a Try/Catch block to capture an error. Setting the error to a variable and then checking that variable is the best way to ensure that you are handling that error when a Try/Catch will not work. The reason that I chose to handle an error at this point in the script is because I know that I may receive errors because an enabled analytic or debug log with no events in it will return an error.

Finally, I will leave you with the one-line version of my solution. Mind you, it does not check for Administrator because that was not an original requirement. It also does not send any verbose messages about logs that exist with no events. Again, this was not the requirement. The following line of code rigidly matches all of the design points. It’s not something I would have submitted. It’s sure to make some of the other judges cringe due to its use of aliases. However, if I read this line of code, I would have graded it as perfect:

Get-WinEvent -ListLog * -Force |? {$_.IsEnabled } |% {if ($_.LogType -match '^(Analytical|Debug)$') { $_ |Get-WinEvent -Oldest -ea SilentlyContinue|select -First 1 } elseif ($_.RecordCount) {$_ |Get-WinEvent -MaxEvents 1 }} |sort TimeCreated -Des |Format-List TimeCreated, LogName, Id, Message

~Tome

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 8.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 


Expert Commentary: 2012 Scripting Games Beginner Event 7

$
0
0

Summary: Microsoft PFE, Michael Frommhold, provides expert commentary for 2012 Scripting Games Beginner Event 7.

Microsoft Scripting Guy, Ed Wilson, is here. Michael Frommhold is the expert commentator for Beginner Event 7.

Photo of Michael Frommhold

Michael is a senior premier field engineer for Microsoft Germany. His technology foci are Active Directory, development (.NET, PoSh, VBS) and platforms. Apart from supporting customer Active Directory infrastructures, he provides workshops and customized knowledge transfers to teach customers how to implement coding and scripting against Active Directory and platform technologies.

In beginner event 7, you are required to display a list of all enabled logs on the computer that contain at least one entry.

Solution

If we open the Event Viewer management console, we see some event logs in the root of the Windows Logs folder and a huge number nested underneath in Applications and Services Logs.

All the event logs that are visible in these folders can be collected through the WMI class Win32_NTEventlogFile or the Windows PowerShell cmdlet Get-EventLog (because Get-EventLog is a wrapper around Win32_NTEventlogFile). The reason that you cannot see all the event logs underneath Microsoft, for example, is that Win32_NTEventlogFile is only enumerating in the root of %SystemRoot%\System32\Winevt\Logs folder for event logs as shown here:

If you call the following command from Windows PowerShell, you will get the same list of event logs as shown in the previous image.

Get-EventLog -list | Format-Table Log

Here is the list that is generated:

Log                                                                                                                                                                         

---                                                                                                                                                                          

ActivIdentity                                                                                                                                                                

Application                                                                                                                                                                 

HardwareEvents                                                                                                                                                               

HP Connection Manager                                                                                                                                                        

Internet Explorer                                                                                                                                                           

Key Management Service                                                                                                                                                       

Media Center                                                                                                                                                                 

OAlerts                                                                                                                                                                     

ODiag                                                                                                                                                                        

Operations Manager                                                                                                                                                           

OSession                                                                                                                                                                    

Security                                                                                                                                                                     

System                                                                                                                                                                       

Windows PowerShell

Unfortunately this list contains only a partial result of the information that we are looking for. Because we know that we can get the list of all present event logs through the command-line utility, wevtutil.exe, by calling:

wevtutil el

Plus, we know we can collect the information about the enabled state of an event log by calling:

wevtutil gl <logname>

Plus, how many entries are in the event log by calling:

wevtutil gli <logname>

To script the concatenation of these three calls would definitely not meet the Scripting Games quality standard, so hopefully there's something we can call from Windows PowerShell directly.

And lucky us—there is another cmdlet that will do the trick:

Get-WinEvent -ListLog *

If we do not call the Windows PowerShell cmdlet from an elevated prompt, we will get some errors (like when retrieving information about the Security event log). To avoid the error messages and to collect design points, we use the ability to set common parameters. In particular we set:

-ErrorAction 'SilentlyContinue'

…which results in…

Get-WinEvent -ListLog * -ErrorAction 'SilentlyContinue'

The next design point to meet is to display only enabled event logs with at least one entry in the log.

To find out what properties we can use, let's inspect the type of objects that are returned by the Get-WinEvent call:

Get-WinEvent -ListLog * -ErrorAction 'SilentlyContinue'  | Get-Member

And the properties are:

Name

----

RecordCount

IsEnabled

Cool. There are the two properties that expose the information we are looking for, so let's pipe this into a Where-Object cmdlet:

Get-WinEvent -ListLog * -ErrorAction 'SilentlyContinue'  |

Where-Object{$_.IsEnabled -and $_.RecordCount -gt 0}

What should come next? The sorting—to give us the event log with highest number of entries in the first row. That's easy. We just pipe the result of the Where-Object cmdlet into a Sort-Object cmdlet and sort it by RecordCount in a descending order:

Get-WinEvent -ListLog * -ErrorAction 'SilentlyContinue'  |
Where-Object{$_.IsEnabled -and $_.RecordCount -gt 0} |
Sort-Object -Property RecordCount -Descending

We are nearly finished with our one-liner. The last thing to do is select the properties that we want to show as output (LogName and RecordCount). So we have to pipe the result from the Sort-Object cmdlet to the Format-Table cmdlet:

Get-WinEvent -ListLog * -ErrorAction 'SilentlyContinue'  |
Where-Object{$_.IsEnabled -and $_.RecordCount -gt 0} |
Sort-Object -Property RecordCount -Descending |
Format-Table Logname, RecordCount

And here you go…here is what we see in the output window:

Image of command output

Have fun with testing!

~Michael
   PFE | Have keyboard. Will travel.

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 8.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Expert Commentary: 2012 Scripting Games Advanced Event 8

$
0
0

Summary: Jeremy Engel, provides expert commentary for 2012 Scripting Games Advanced Event 8.

Microsoft Scripting Guy, Ed Wilson, is here. Jeremy Engel is the expert commentator for Advanced Event 8.

Image of Jeremy Engel

Jeremy works in the health care industry as a lead systems engineer and architect, promoting new technologies and helping drive their acceptance and implementation. Being a fanatic of efficiency and automation, he also focuses on developing programs and scripts to ease the burden of administration for himself, his colleagues, and the community. His most notable contribution thus far is the PowerShell Module for DHCP. He is currently working on releasing a multitude of other modules and scripts.

He is a great admirer of the Windows PowerShell community and is honored to be a judge for this year’s Scripting Games. He wishes all the contestant’s happy scripting and good luck! Jeremy’s proudest contributions to this world are his three wonderful children, who together with his beautiful wife live in the bustling metropolis of Oak Ridge, North Carolina.

When I was developing my script for the 2012 Scripting Games Advanced Event 8, the first question I asked myself was how best to differentiate between wired and wireless connections. I began by examining the Win32_NetworkAdapter class, but I couldn’t find any reliable method therein of determining the physical media type. I thought about scanning the NetConnectionID for indicators like “Wireless” or “Local Area Connection” but those were horribly imprecise, especially given the ability of users to rename them to whatever they wanted. Even without renaming the network connection on my Win8 slate, I found that the wired adapter was named “Wired Ethernet Connection” and the wireless adapter, “Wi-Fi.” As you can see, there was just no way to plan for all the possibilities. Now, as it happened, I had the beta copy of Windows PowerShell 3.0 installed on my laptop, so on a whim I typed “Get-Net” and tabbed out. To my delight a Get-Net6to4Configuration cmdlet popped up, and two tabs later, I came upon Get-NetAdapter!

Lo and behold, there it was: the PhysicalMediaType property, and it differentiated between 802.11 (wireless) and 802.3 (wired) among others. While the NetAdpater.Types.ps1 xml says that the PhysicalMediaType strings will appear as “802.3” and “Native 802.11,” I decided not to use the –eq operator when filtering, but rather the –match operator, just in case additional 802.3/11 media types would be defined in the future. I also wanted to differentiate between connection state and device state. The AdminStatus property worked best for the device state, with its Up and Down designations. And although the Status property displayed aspects of the connection state, it appeared to be a viewer-friendly overall status pulling from multiple sources. That’s good for what it is, but a truer property to determine the connection state seemed to me to be MediaConnectionState.

Why did I care about the connection state when the event parameters didn’t call for any such analysis? When writing a script, I always try to think about who is going to use the script and what they might be expecting. Thus I wanted to show a warning message should the adapter that’s toggled into the enabled state be disconnected. That way the user can take corrective action right away, whether that be to plug-in a network cable or join a wireless network, rather than determine at some later point that they are not connected to any network.

As part of the Event 8 requirements, users are to be prompted if more than one of the network adapters are enabled or disabled. I planned for that and then took it a step further and decided to give the user the ability to specify which adapter(s) they wanted to include in the toggling process. That would allow them to bypass the multiadapter prompt.

Lastly, by typing Get-Command –Noun NetAdapter into Windows PowerShell, I found the Disable and Enable companion cmdlets that I would need to complete my script’s functionality.

With my requirements and desired logic delineated, writing the script was pretty simple. I separated the logic for selecting the appropriate adapter and put it in its own function for two reasons: one, I wanted to be able to loop should the user provide an invalid selection; and two, I needed to use the code in four different instances and I didn’t want to have to repeat the same code over and over again. Also, I discovered that I needed to add a Start-Sleep line to give the newly enabled network adapter a chance to connect.

To put a pretty bow on the script, I added regions so that readers could easily understand the logical stages of the script, and then added a Help file for reference in Windows PowerShell. Here is the entire script:

Switch-NetworkConnection.ps1

<#

  .Synopsis

   Toggles the enabled network connection between a wired and a wireless network adapter.

  .Description

   The Switch-NetworkConnection.ps1 script toggles the enabled network connection between a wired and a wireless network adapter.

 

   This script can only be used on mobility platforms with PowerShell 3.0 installed and must be run as Administrator. Furthermore, only one wired and one wireless network adapter can be selected to take part in the toggling process. You can either select the desired network adapters from a dispalyed list, or specify which adapters will take part using the available parameters.

  .Parameter WiredNetworkAdapter

   This parameter specifies the wired network connection that will be used in the toggling process.

 

   This accepted value for this parameter is either the name of the network adapter or a NetAdapter object representing that network adapter.

  .Parameter WirelessNetworkAdapter

   This parameter specifies the wired network connection that will be used in the toggling process.

 

   This accepted value for this parameter is either the name of the network adapter or a NetAdapter object representing that network adapter.

  .Example

   .\Switch-NetworkConnection.ps1

 

   This example determines the wired and wireless network adapters that will be toggled. If multiple network adapters of a given type are found, the script will prompt for a choice.

  .Example

   .\Switch-NetworkConnection.ps1 -WiredNetworkAdapter "Local Area Connection" -WirelessNetworkAdapter "WLAN 2"

 

   In this exmaple, the wired and wireless adapters were specified because multiple network adapters of each type are present and the user wanted to bypass the network adapter selection process.

  .Outputs

   Microsoft.Management.Infrastructure.CimInstance[]

  .Notes

   Name:         Switch-NetworkConnection.ps1

   Author:       Jeremy Engel

   CreatedDate:  03.26.2012

   ModifiedDate: 03.29.2012

   Version:      1.0.0

#>

 

#Requires -version 3.0

Param([Parameter(Mandatory=$false,Position=0)][Alias("Wired","LAN")][PSObject]$WiredNetworkAdapter,

      [Parameter(Mandatory=$false,Position=1)][Alias("Wireless","WLAN")][PSObject]$WirelessNetworkAdapter

      )

 

function Get-AdapterSelection {

  Param([Parameter(Mandatory=$true)][string]$Text,

        [Parameter(Mandatory=$true)][Microsoft.Management.Infrastructure.CimInstance[]]$Adapters

        )

  Write-Host $Text

  for($i=0;$i-lt$Adapters.Count;$i++) { Write-Host "  $($i+1). $($Adapters[$i].Name)" }

  $n = [int](Read-Host "Selection")

  if($n -lt 1 -or $n -gt $Adapters.Count+1) {

    Write-Host "Invalid selection." -ForegroundColor Red

    return (Get-AdapterSelection -Type $Type -Adapters $Adapters)

    }

  else { return $Adapters[$n-1] }

  }

 

function Main {

  #region System Requirements and Runspace Validation

  if(!(Get-WmiObject -Class Win32_Battery)) {

    Write-Host "ERROR: This script is designed for use on laptops and tablets only." -ForegroundColor Red

    return

    }

  if(([Security.Principal.WindowsIdentity]::GetCurrent()).Owner -ne "S-1-5-32-544") {

    Write-Host "ERROR: This script may only be run as Administrator. Please open a PowerShell window as Administrator and try again." -ForegroundColor Red

    return

    }

  #endregion

  #region Adapter Validation and Selection

  $adapters = Get-NetAdapter -ErrorAction Stop

  $wired = $adapters | Where-Object { $_.PhysicalMediaType -match "802.3" }

  $wireless = $adapters | Where-Object { $_.PhysicalMediaType -match "802.11" }

  if(!$adapters -or !$wireless -or !$wired) {

    $type = if(!$adapters){"any"}elseif(!$wireless){"any wireless"}else{"any wired"}

    Write-Host "ERROR: You do not have $type network adapters." -ForegroundColor Red

    return

    }

  if($WiredNetworkAdapter) {

    $wired = if($WiredNetworkAdapter -is [string]) { $wired | Where-Object { $_.Name -eq $WiredNetworkAdapter } }

             elseif($WiredNetworkAdapter -is [Microsoft.Management.Infrastructure.CimInstance]) { $WiredNetworkAdapter }

             else { $null }

    if(!$wired) {

      Write-Host "ERROR: Could not locate a wired network adapter by the name of $WiredNetworkAdapter." -ForegroundColor Red

      return

      }

    }

  if($WirelessNetworkAdapter) {

    $wireless = if($WirelessNetworkAdapter -is [string]) { $wireless | Where-Object { $_.Name -eq $WirelessNetworkAdapter } }

                elseif($WirelessNetworkAdapter -is [Microsoft.Management.Infrastructure.CimInstance]) { $WirelessNetworkAdapter }

                else { $null }

    if(!$wireless) {

      Write-Host "ERROR: Could not locate a wireless network adapter by the name of $WirelessNetworkAdapter." -ForegroundColor Red

      return

      }

    }

  if($wired.Count -gt 1) {

    $text = "$($wired.Count) wired network adapters were found on your system. Please select the desired network adapter by number."

    $wired = Get-AdapterSelection -Text $text -Adapters $wired

    }

  if($wireless.Count -gt 1) {

    $text = "$($wireless.Count) wireless network adapters were found on your system. Please select the desired network adapter by number."

    $wireless = Get-AdapterSelection -Text $text -Adapters $wireless

    }

  #endregion

  #region Action Determination

  if($wired.AdminStatus -eq "Down" -and $wireless.AdminStatus -eq "Down") {

    $text = "Both network adapters are disabled. Choose the number of the network adapter you wish to enable."

    $enableMe = Get-AdapterSelection -Text $text -Adapters $wired,$wireless

    $disableMe = $wired,$wireless | Where-Object { $_.Name -ne $enableMe.Name }

    }

  elseif($wired.AdminStatus -eq "Up" -and $wireless.AdminStatus -eq "Up") {

    $text = "Both network adapters are enabled. Choose the number of the network adapter you wish to disable."

    $disableMe = Get-AdapterSelection -Text $text -Adapters $wired,$wireless

    $enableMe = $wired,$wireless | Where-Object { $_.Name -ne $disableMe.Name }

    }

  else {

    $enableMe = $wired,$wireless | Where-Object { $_.AdminStatus -eq "Down" }

    $disableMe = $wired,$wireless | Where-Object { $_.AdminStatus -eq "Up" }

    }

  #endregion

  #region Action Execution

  $enableMe | Enable-NetAdapter -ErrorAction Stop

  $disableMe | Disable-NetAdapter -Confirm:$false -ErrorAction Stop

  Start-Sleep -Seconds 2 # Pause while the enabled adapter establishes a connection

  #endregion

  #region Output

  $adapters = Get-NetAdapter

  $check = $adapters | Where-Object { $_.Name -eq $enableMe.Name }

  if($check.MediaConnectionState -eq "Disconnected") {

    Write-Host "WARNING: The enabled network adapter [$($check.Name)] is in a disconnected state." -ForegroundColor Yellow

    }

  $adapters

  #endregion

  }

Main

~Jeremy

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 9.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

Expert Commentary: 2012 Scripting Games Beginner Event 8

$
0
0

Summary: Microsoft PFE, Chris Bellee, provides expert commentary for 2012 Scripting Games Beginner Event 8.

Microsoft Scripting Guy, Ed Wilson, is here. Chris Bellee is the expert commentator for Beginner Event 8.

Image of Chris Bellee

Chris is a premier field engineer (PFE) based in Sydney, Australia. He teaches many Windows PowerShell workshops and custom classes, as well as works on IP development that's delivered worldwide to Microsoft Premier Customers. He also trains and certifies other field engineers to deliver Windows PowerShell workshops in the APAC region.

Chris is also a directory services PFE with a passion for helping customers monitor and automate their Active Directory infrastructure. He has developed many sample Windows PowerShell solutions for customers to enable them monitor and manage Active Directory.

Having previously worked as a systems engineer, Chris has extensive experience developing solutions by using a variety of languages other than Windows PowerShell, such as VBScript, Perl, JavaScript, and C# to aid his daily tasks.

In beginner event 8, you are required to determine if a computer is a desktop computer or a laptop computer:

Event scenario

You are the desktop manager at a midsized enterprise company. It is inventory time, and you need to get a count of the number of laptop computers and the number of desktop computers. You decide to write a Windows PowerShell script that will count the number of desktop computers and the number of laptop computers on the network. To permit auditing, your report should include the computer name, and whether or not it is a desktop or a laptop machine.

Design points

  • For the purposes of this scenario, your script only needs to write to the console.
  • Your script only needs to determine laptop or desktop from a hardware perspective. You do not need to determine the version of the operating system.
  • Your code only needs to run on a local computer.
  • If your code requires admin rights, you should detect if the code is running as an admin or as a standard user. If your code works without requiring admin rights, you do not need to make this check.
  • Extra points for writing a simple function that only returns a Boolean value.

Solution

For this challenge we need to find a way to determine whether a computer is a laptop or desktop. Because the scenario states that the script should collect information from remote machines, our obvious choice to employ Windows Management Instrumentation (WMI) for the job.

The first decision is which WMI class contains the data that we are interested in. In this case, there are two classes that fit the bill: Win32_ComputerSystem and Win32_SystemEnclosure. Because Windows PowerShell provides first class support for the WMI object model, it is relatively trivial to query these classes and browse the available properties by using the Get-WMIObject cmdlet.

Get-WmiObject -Class Win32_ComputerSystem | Format-List *

Get-WmiObject -Class Win32_SystemEnclosure | Format-List *

The PCSystemType property in Win32_ComputerSystem contains a number that represents the form-factor of the machine. This seems to be a perfect fit until you read the MSDN Win32_ComputerSystem class documentation. The PCSystemType property is not available on computers running Windows XP, Windows Server 2003, Windows 2000, or Windows NT Server 4.0, so this may be less than perfect for organizations where Windows XP is still prevalent.

In contrast, the Win32_SystemEnclosure class is supported on down-level operating systems. Its ChassisTypes property contains just the information we need. If you look at the MSDN class documentation, there are a large number of possible numeric values for this property, it also holds an array data type, so attention has to be given as to how we work with it.

Now that we have the correct piece of data, we can create a function that returns a Boolean value depending on whether the target machine has a laptop or desktop form-factor. The function is named Is-Laptop and it returns a Boolean value. It has a single input parameter consisting of the remote computer name to query and a single output variable called $result. The output variable is set to $false at the beginning of the function body.

<#

.Synopsis

   helper function used by Get-HardwareType

.EXAMPLE

   Example of how to use this cmdlet

#>

 

function Is-Laptop {

 

[CmdletBinding()]

[OutputType([boolean])]

 

    param

    (

    [Parameter(Mandatory=$true)]

    [string]

    $strHostName

    )

 

    $blnResult = $false

  

        $objWMI = Get-WmiObject -ComputerName $strHostName -Query $query -ErrorAction Stop

 

          switch ($objWMI.ChassisTypes) {

       

            9  {$blnResult = $true} # Laptop

            10 {$blnResult = $true} # Notebook

            12 {$blnResult = $true} # Docking Station

            14 {$blnResult = $true} # Sub Notebook

            default {}

          }

          return $blnResult

     } # end function

Looking at the documentation for the Win32_SystemEnclosure class, you can see that there is more than one numerical value that determines if a machine is “portable.” For this reason I chose to use a switch statement to determine which of the four values that we are interested in are set. Another bonus to using a switch instead of an ‘if’ statement is that it can automatically deal with arrays. The ChassisTypes property holds an array of numbers. Although most of the time the property holds a single value, it is possible that it can hold many values. The switch statement acts like a pipeline—each item in the array flows through the statement one-by-one.

Although the Is-Laptop function does all the work of executing the WMI query and returning a Boolean value, we define a second function that executes it. This makes the code more legible and abstracts the actual WMI query from the name resolution and error handling functionality implemented in the Get-HardwareType function.

Notice the process {} scriptblock that contains most of the code in the Get-HardwareType function. This allows the function to process machine names as pipeline input.

"pc01","pc02","pc03" | Get-HardwareType

Next, we try to resolve the short computer name to a fully qualified DNS host name by using the GetHostByName() .NET static method. A new object instance is not needed to use the method. We can simply reference the type name and call the method by using the double-colon (::) accessor syntax.

$objHostName = [system.net.dns]::GetHostByName($hostName)

Notice that the GetHostByName() method call is contained within a Try/Catch block. This will allow any name resolution failures to bypass the rest of the function, simply printing an error to the user and allowing the function to continue execution.

Before executing the WMI query, we use the Test-Connection cmdlet to determine whether the computer is accessible, using an ICMP (ping) packet. If this check is not performed, the WMI query will time-out when a computer is not available, slowing the script execution considerably. The Test-Connection cmdlet returns a Boolean value ($true) if the machine is contacted successfully, allowing us to use it directly within an ‘if’ statement condition.

if (Test-Connection -ComputerName $objHostName.HostName -count 1 -erroraction silentlycontinue)

The final part of the function uses another Try/Catch block to enclose the call to the Is-Laptop function, again allowing the script to recover from a potential terminating error.

$objResult = New-Object -TypeName psobject -Property @{

HostName=$objHostName.HostName;IsLaptop=(Is-Laptop -strHostName $objHostName.HostName)}

The previous line creates a new Windows PowerShell object to store the name of the computer that is being tested and a Boolean value that indicates whether it is a laptop or a desktop machine. Here, we are using –Property to declare a hash table of name and value pairs that populate the new object’s members. The Is-Laptop property stores the result of calling the Is-Laptop function, which is a Boolean value.

The main script execution occurs at the bottom of the script. We declare two counter variables to hold the number of desktops or laptop computers that are found.

$laptopCount = 0

$desktopCount = 0

To provide some input to the Get-HardwareType function, we search the local Active Directory domain for the CN attributes of all computer objects that don’t have the string server within their OperatingSystem attribute, using a DirectorySearcher object. The search filter is specified by the LDAP query language that follows.

(&(objectcategory=computer)(!operatingsystem=*server*))")

The search is executed by calling the FindAll() method of the DirectorySearcher object and the search results are saved in the $arrMachine variable. The variable should now contain an array of short computer names that can be passed through the pipeline to the Get-Hardware function. Each computer will then be connected to and evaluated, and the results will be displayed on the console.

$result = $arrMachineName | Get-HardwareType

$result

The total number of laptop and desktop form-factors can now be calculated. The $result variable contains an array of psobjects that are passed to a ForEach-Object cmdlet that increments the $laptopCount and $desktopCount variables, depending on whether the current object’s islaptop property is $true or $false.

Finally, the totals can be written to the console.

"Laptop Total: $laptopCount"

"Desktop Total: $desktopCount"

Following is the full script.

<#

.Synopsis

   helper function used by Get-HardwareType

.EXAMPLE

   Example of how to use this cmdlet

#>

 

function Is-Laptop {

 

[CmdletBinding()]

[OutputType([boolean])]

 

    param

    (

    [Parameter(Mandatory=$true)]

    [string]

    $strHostName

    )

 

    $blnResult = $false

  

        $objWMI = Get-WmiObject -ComputerName $strHostName -Query $query -ErrorAction Stop

 

          switch ($objWMI.ChassisTypes) {

       

            9  {$blnResult = $true} # Laptop

            10 {$blnResult = $true} # Notebook

            12 {$blnResult = $true} # Docking Station

            14 {$blnResult = $true} # Sub Notebook

            default {}

          }

          return $blnResult

     } # end function

    

<#

.Synopsis

  function to determine chassis type using a WMI query

.DESCRIPTION

   function to determine chassis type using a WMI query

.EXAMPLE

   "pc01","pc02","pc03" | Get-HardwareType

#>

 

function Get-HardwareType {

 

[CmdletBinding()]

[OutputType([psobject])]

 

Param

(

[Parameter(Mandatory=$true,ValueFromPipeline=$true)]

$strHostName

)

 

process {  

 

    try {

 

        $objHostName = [system.net.dns]::GetHostByName($strHostName)

 

        $query = "select __SERVER,ChassisTypes from Win32_SystemEnclosure"

 

            if (Test-Connection -ComputerName $objHostName.HostName -count 1 -erroraction silentlycontinue) {

 

            try {        

                $objResult = New-Object -TypeName psobject -Property @{HostName=$objHostName.HostName;IsLaptop=(Is-Laptop -strHostName $objHostName.HostName)}

                return $objResult

                }

           

          catch {

                "Error trying to query $($objHostName.HostName)"

                }

            }

       else {

            write-host "error connecting to $($objHostName.HostName)"

            }

    }

    catch {

    write-host "Unable to resolve DNS address for $strHostName"

    }

  }

} # end function

 

###################################################

# Main script execution

###################################################

 

$laptopCount = 0

$desktopCount = 0

 

$searcher = new-object directoryservices.directorysearcher([ADSI]"","(&(objectcategory=computer)(!operatingsystem=*server*))")

[void]$searcher.PropertiesToLoad.Add("cn")

$arrMachineName = $searcher.findall() | %{$_.properties.cn}

 

$result = $arrMachineName | Get-HardwareType

$result

$result | ForEach-Object {if ($_.islaptop) {$laptopCount++} else {$desktopCount++}}

 

"Laptop Total: $laptopCount"

"Desktop Total: $desktopCount"

~Chris

2012 Scripting Games Guest Commentator Week Part 2 will continue tomorrow when we will present the scenario for Event 9.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy 

Beginner Leaderboard for the 2012 Scripting Games as of April 25

$
0
0

This is the Beginner leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day as event submissions are graded by the judges. No more scripts are being accepted. Due to the large volume of submissions, the grading time has been extended for our busy judges.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Beginner Events

User Name

Total Points

Scripts Rated

Total Ratings

Lido Paglia

48.25

10

23

Sahal Omer

47.17

10

22

Mike F Robbins

46.45

10

31

Dawn Villejoin

46.23

10

31

arnold moreno

45.87

10

24

Chris Manning @pbchris

44.83

10

24

yellowscope

44.67

10

26

Mr_Motown

44.17

10

26

JeffWouters

44.13

10

32

Matt benton

43.83

10

23

Cliff Harrison

43.75

10

24

wschoier

43.67

10

21

Srikanth

43.5

10

25

Eric Pankowski

43.5

10

24

TechguyTJ

43.5

10

25

Adam Funck

43.25

10

22

Andy Mello

43

10

23

Neil Clinch

42.75

9

20

Don Hunt

42.67

10

23

Charlie Jacobson

42.5

10

24

Thiyagu

42.33

9

19

Paul Hiles

42.33

10

22

Grzegorz Kulikowski

42.33

10

21

Eleftheria Theologou

42.27

10

23

CraigJahnke

42.17

10

22

Daniel Killian

42

10

24

ckrull

41.92

10

27

James McNeil

41.92

10

23

qsilverx

41.9

10

25

Jordan Davis

41.83

10

24

ScriptingWife

41.58

10

28

Maciej

41.5

10

24

Chris-D

41.5

10

23

Jhonny Yamaniha

41.42

10

25

Brian Bohanon

41.25

10

24

JoeTea

41.25

10

20

NCoppersmith

41.17

10

21

David OBrien

41

10

22

jaydee

41

10

23

GCaporale

41

10

27

Duffman

41

10

27

mtb44

41

10

23

Tim Muessig

40.92

10

25

mark_@_li

40.67

10

21

James Berkenbile

40.67

10

24

Julie Andreacola

40.58

10

23

Sigitas Grėbliūnas

40.5

9

19

James White

40.5

10

26

David Waderich

40.33

10

22

tyoung

40.25

10

25

Tim Watson

40.2

10

25

Vinay Bhandari

40.08

10

22

Alexis Ragual

40

9

19

AballahSonDis

40

10

22

Michael Moore

40

10

23

AmandaD

39.92

10

23

NakiPS1

39.83

10

24

Steven Neel

39.67

9

18

Nathan Mayberry

39.67

10

20

John Grenfell

39.58

10

23

SM Yeoh

39.5

10

22

Max Schnell

39.33

9

17

Werner

39.25

10

26

Marcin Pietras

39.17

9

18

John Russell

39.17

10

24

Erica Miles

39.17

10

24

Joshua Taylor

39.1

10

26

clbarnett

39

10

23

Mark P

38.92

9

23

ICC_jruff

38.83

10

21

ngebhar2

38.83

10

23

BTmuney

38.83

10

25

Andrey Zvyagin

38.75

10

23

Andy Bidlen

38.67

9

21

Rich Oswald

38.67

10

22

cemarsh06

38.67

10

23

SLevenberg

38.67

10

21

Matt Tilford

38.5

10

25

TSCSG

38.5

10

22

Chris Seiter

38.33

10

21

Brian Sabatini

38.33

10

23

Shaun Watts

38.25

10

22

Jeremy Cox

38.17

10

23

blahcubed

38

9

18

L4NM4N

38

10

24

MikeHowden

37.92

9

20

SdeDot

37.83

10

24

Steve Hall

37.83

10

21

James Stallwood

37.75

9

21

Pradeep Rawat

37.67

10

24

Lotte

37.67

10

23

Fabio Jr

37.67

10

21

rumart

37.5

10

24

Dominic Leonard

37.42

10

21

Jason Y.

37.33

10

23

Dexter Dhami

37.25

9

21

Derek Schauland

37.17

9

21

BradC

37.17

10

23

Ken Wilson

37.17

10

25

Xander Solis

37

10

25

NSlearningPS

37

10

20

Oleg Suchkov

36.9

10

22

Ifiok Moses

36.83

10

23

John OHarra

36.82

10

26

Robert B

36.67

10

23

emekm

36.5

10

21

Wouter Beens

36.42

10

21

Daniel Thompson

36.33

10

23

Leon Nell

36.33

10

25

Andreas Engkvist

36.33

10

23

Tyson J. Hayes

36.17

10

21

ICC_mworthley

36

10

25

Yves PASCAULT

36

10

21

DaveyK

35.92

10

24

Geathan

35.87

10

22

DrLe

35.75

9

22

NGelotte

35.67

8

17

ruskie

35.42

9

21

Elmerp

35.33

10

19

dluke001

35.08

10

23

Jess Pomfret

35

10

23

Jon McCormick

34.92

10

25

Nadeem Vance

34.83

9

20

Phill McSherry

34.83

9

22

David Christian

34.83

10

22

ICC_RichardEisenberger

34.75

10

25

therceg

34.67

9

19

Stephen Correia

34.67

10

21

Riwe

34.67

10

23

John

34.6

9

21

Nathan Lare

34.5

9

19

Dave Maldonado

34.42

9

20

AnotherPoShBlog

34.4

9

20

member2712

34.33

10

22

eribaq

34.27

10

24

Roy M

34.17

9

20

BreakDown

34

10

27

Daniel Dittenhafer

34

10

22

JeremyB

33.92

10

23

Mads Hjort Larsen

33.83

10

22

Norman Manoh

33.5

10

21

Nisha Sridhar

33.33

8

16

Timo Skupin

33.33

10

25

Nate Shepard

33.17

10

21

cphair

33

9

17

Will Nevis

32.75

10

23

Shevek

32.67

9

20

honeybadger

32.5

8

18

Aaron Bednar

32.5

10

22

Marty

32.3

9

21

Daniel Snowden

31.92

9

20

Zak Humphries

31.58

8

19

TheKidd

31.5

8

14

shiv

31.42

9

21

mand0

31.33

8

16

Zia

31.33

9

21

Mod10

31.33

10

25

Daniel Bicho

31.08

9

23

MarkIsBack

30.67

8

19

ResetSA

30.67

9

20

BernhardG

30.5

8

17

andre

30.5

8

20

Carl

30.42

8

23

mvanhorenbeeck

30.42

8

21

jones89

30.17

10

25

aaron d

30

10

22

erunama

29.75

10

24

Vern Anderson

29.67

10

23

Matt Swint

29.58

8

20

nyoro2

29.5

7

16

Pendrag

29.5

8

15

Scott Baker

29.08

8

20

The Awesome-Machine.NET

29

9

21

mnadobnik

28.75

8

18

eklime

28.58

7

18

Clancy Wendt

28.33

9

21

kloinerFeigling83

28.08

9

21

Scott Alvarino

28

8

18

Brian Fraley

27.92

8

19

Dan

27.92

8

19

oki

27.5

8

15

MOW

27.5

8

17

W. Sterling

27.5

8

20

real fastcomputer

27.5

9

19

Andrew Morgan

27.42

7

18

Dennis James

27.33

7

14

Gica

27.15

7

19

Mouton

27.08

8

20

Matt McAllister

27

8

20

Stephen Brown

26.67

7

16

Japke

26.5

7

17

Sai Prasad Vaddepally

26.33

8

16

Clayton McKenzie

26.25

8

22

Chuck Lathrope

25.77

8

19

Sidewinder

25.5

7

18

Tony Rad

25.5

8

21

aalaminos

25.42

7

18

Marcos Tsuda

25.42

8

17

catremor

25.25

7

17

mrgif1

25

6

12

Joe Keohan

25

9

20

Steve Mahoney

24.75

8

18

something easier to read

24.58

7

18

BenJT

24.5

7

18

Niel Fletcher

23.5

7

14

Jason Omar

23.25

6

18

ICC_KFoley

23.17

7

20

Kryten-68

23

7

18

Emil Eriksson

23

7

16

Derrick Michelson

22.83

7

17

Mathieu Boulard

22.75

5

15

Kieran Walsh

22.67

7

15

robert broyles

22.5

8

19

jarheadf23

22.25

6

14

octavmarius

22.17

5

12

toumi walid

22.17

7

20

EDW

22

7

13

Vinay Thakur

21.83

10

22

Trevor Watkins

21.5

7

17

Shawn Melton

21.33

5

13

Chris Keim

21.33

6

15

Tony Uren

21

6

15

e46d8dd2e1625c7a6182b82bc012a7e0

20.5

8

20

Mckie

20.47

7

17

Luke Forder

19.92

5

16

Megha Kuruvilla

19.67

5

12

jbrek

19.33

6

15

HitchHeik

19.17

6

16

Jeff Schulman

19

5

12

Mooseade

18.8

5

14

vNiklas

18.75

5

13

Shaun Gibbs

18.5

7

14

Shawn bequette

18.33

6

14

Daniel Headley

18.17

5

10

Andrew Dauncey

17.83

5

11

John van Leeuwen

17.58

6

15

Bastien B

16.5

5

16

Richard Holman

15.5

5

9

ed3c64f9163ea026e949706ee53b2a34

15

5

10

Colyn1337

14

3

5

lamaar75

13.33

5

13

joeartz

13

3

8

Matt Vidrine

12

3

8

Chris Albert

11.33

3

6

Hov Arve

11.17

4

10

Patrik Lindström

10.5

3

9

Bret Ridenour

10.5

4

12

Paul Sweeney

10.5

4

8

Benduru

10

4

8

Darren Maspero

9

2

8

vbscripter

9

2

4

Peter Heydon

8.92

2

7

Tim Miller

8.67

3

11

Brendan Erofeev

8.5

2

6

DWS

8.42

2

7

Dennis Jarjosa

8.42

2

7

plindgren

8.42

3

11

Yuri Kutovoy

8.42

3

11

Matt_A_

8.42

3

9

lvimeux

8.33

2

6

Jan R.

8.33

2

6

Arif Ali

8.33

3

10

Anders Wang

8.33

3

6

Jerame Caudill

8

2

6

Thomas Farmer

8

2

6

Andy Wyse

8

3

9

TomKupka

7.83

3

11

sfibich

7.75

2

7

Francisco Puig Diaz

7.75

3

11

Bryan

7.67

2

4

Mark Amann

7.67

2

6

Forrest Stanley

7.67

2

6

Name

7.6

3

10

Tomek A.

7.5

2

8

MarcoB78

7.42

2

7

TaylorGibb

7.4

2

8

Kevin

7.33

3

8

Michael Odermatt

7.08

2

7

Jeffrey Jacobs

7

2

6

Greg Combs

7

3

7

Scott Button

6.83

2

7

Sander

6.83

2

7

Coderaven

6.33

2

5

u2tb

6.33

2

6

Jeff Maes

6

2

6

Harshul

6

2

3

JMARCH

6

2

4

sebuko

5.75

2

6

greeme

5.67

2

6

Apnea

5.67

2

6

Satheesh

5.67

2

7

Timm Brochhaus

5.5

2

6

Jonny Earl Grey Lindbom

5.47

2

8

radek

5.42

2

7

Josh Nylander

5.42

2

7

TheZmann

5.33

2

4

Dave Baird

5.33

2

6

RJSN

5.33

2

4

DisplayName

5.33

2

5

Anthony Rum

5.25

2

7

Mike Lambert

5.25

2

7

Andrew Cameron

5

1

3

foobar

5

1

2

Dean Grant

5

1

3

Brian Wuchner

5

2

8

Joel Cook

5

2

6

miramar_unna

5

2

4

Mallika Gogulamudi

5

2

8

acchong

4.75

1

4

Ken King

4.5

1

2

Sudeep Bhaskar

4.5

1

4

Petter Edin

4.33

2

6

Andrew Gardner

4.25

1

4

Jason Schmidtlein

4.25

1

4

Ryan Youngs

4

1

3

Pavan Hotha

4

1

3

zacd

4

1

3

Claymonster

4

1

3

Francisco osorio

4

1

3

Filip Rejch

4

1

2

James B. Bizzell

4

1

2

Jay Lockard

4

1

3

evidence

4

1

3

PSLearner

4

2

6

peter bishop

4

2

8

Björn

4

2

3

Dominic Daigle

3.85

2

9

Ola Skjeldal

3.67

1

3

Brett Chandler

3.67

1

3

Tim Hetzel

3.67

1

3

Chris Watson

3.67

2

5

Bob__Mule

3.5

1

4

sgatepunk

3.5

1

2

ocongil

3.33

1

3

Jasper van der Heijden

3.33

1

3

70f53217af68ac357dfc1a46739257a6

3.33

1

3

MonitorMan

3.33

1

3

iTodd

3.33

1

3

Jonathan Birkett

3.33

1

3

redi311

3.33

1

3

Dexter

3.33

2

6

b4d93r

3.33

2

5

jeprus

3.25

1

4

skynetx

3

1

3

Jude Croyle

3

1

3

Crystal Diaz

3

1

3

Erin Huligan

3

1

1

Andrew Newman

3

1

3

mitch baker

3

1

3

MrBatchFile

2.67

2

6

Jeremy Dunlop

2.33

1

3

a64c64bd8e1fe90b8b024ab272090e32

2.33

1

3

Daed

2.33

1

3

Jay mac

2.33

1

3

Byty

2

1

3

3166f9ba33499b4658123e7b0a84598f

1.67

1

3

Luca Christmann

1.67

1

3

le4ne

1.5

1

4

Sean Massey

1.33

1

3

David Granlund

1.33

1

3

Anjan Chidurala

1.33

1

3

Chris Nakagaki (Zsoldier)

1.33

1

3

2e638c99ea54b4ddb208033083f4ef24

1.33

1

3

Gabriel Tapia

1.33

1

3

j.vogt

1.33

1

3

TitleRequired

1.33

1

3

Eric Ray

1.25

1

4

Gary Jackson

1.25

1

4

Jason Shaw

1.25

1

4

gary gray

1.2

1

5

TechJLS3

1

1

5

WizardX

1

1

5

Jeremy Kieler

1

1

3

 

Advanced Leaderboard for the 2012 Scripting Games as of April 25

$
0
0

This is the Advanced leaderboard of the 2012 Scripting Games. Keep in mind that the rankings are constantly changing throughout the day as event submissions are graded by the judges. No more scripts are being accepted. Due to the large volume of submissions, the grading time has been extended for our busy judges.

How are scripts scored? Learn more about judging criteria.

 2012 Scripting Games badge

Top Submitters for the Advanced Events

User Name

Total Points

Scripts Rated

Total Ratings

Kevin Hopcroft

46.67

10

18

Kyle Neier

46.5

10

18

Albert Fortes

46.33

10

17

Michał Gajda

44.67

10

20

Jeremy Caauwe

43.5

10

17

Jaap Brasser

42.67

10

15

Rob Campbell

42.33

10

15

Rohn Edwards

42

9

13

Mikko

41.67

10

17

Łukasz Kałużny

41.5

10

13

Robert Mongold

41.5

10

14

Sergey Borisovich

41.5

10

18

Mike Hammond

41.17

10

16

Ed Withers

41

10

17

aml

40.67

10

16

Matthew Painter

40.5

9

15

Tim Parkinson

40.5

9

11

Nuno Mota

40.5

10

16

John Sneddon

40.5

10

15

Prosvetov Roman

40.33

10

19

EasyMac308

40.25

10

19

Brian Wilhite

40

9

18

Francis D

40

9

16

Billy Angers

39.5

9

17

Jason Hofferle

39.5

9

15

Ryan Ries

39.5

10

18

Scott1138

39.5

10

15

Glenn Faustino

39.42

9

19

Aleksey Shuvalov

39.33

9

18

Matthew Graeber

39.17

10

16

BigTeddy

39

9

16

Robert van den Nieuwendijk

39

9

11

Stephanevg

39

10

13

Jason Stangroome

38.67

9

16

gbdixg

38.67

10

17

MSFT-AutomationJason

38.5

9

11

Sergey Vorontsov

38.5

9

12

Joel Reed @J_lR_d {AZPOSH}

38.5

9

11

_Emin_

38

9

16

Pete Maan

38

9

12

Sean Brown Houses

37.83

9

16

KSchulte

37.83

9

16

Matt Gohmann

37.5

9

12

Ken

37.5

9

11

Daniel Howe

36.5

9

11

Igway Jacobs

36

9

13

Rich Kusak

36

9

12

Kim Tram

36

9

11

ICC_RyanDennis

36

10

15

Cesar Mendoza

35.83

10

14

Serkan Varoglu

35.67

9

13

Alex McFarland

35.5

9

14

AZPOSH - Brian T Young

35.5

9

13

Lars Seinwill

35.5

9

14

Jason Cole

35

9

14

Daniel Cruz

35

9

12

Joe D.

35

9

12

Vladimir Stepic

35

9

12

Frederick Duemig

35

9

13

Cameron Wilson

34.25

10

18

Matthew BETTON

34

9

14

Jesper Strandberg

33.5

8

9

blindrood

33

8

12

Joshua Feierman

33

9

12

Robert Eder

33

9

12

Paulo J

32.83

9

14

George Kesler

32.75

8

12

Jason Wood

32.67

9

14

Serg

32.5

10

17

Vincent Van Hecke

32.5

10

15

Ryan C

32

9

14

ICC_JDyer

31.33

8

10

vNoob

31

10

17

Ayo Wu

30.5

8

12

Sam

30.5

8

10

Nathan Linley

30.5

9

14

Yves P

30.5

10

12

Schlauge

30

9

13

Ken Lin

29.5

9

14

Pemo

29

9

12

Grégory LUCAND

28.5

9

14

Thomas Paetzold

28

8

13

SimonW

27.33

6

10

Jack Chang

27.33

7

11

Wes Stahler

26.5

6

7

hemanth.damecharla

25.5

8

10

Ken Hamilton

25

7

12

DamienCharbonnel

23

7

10

Tom_G

20.5

5

8

Franck RICHARD

20

5

7

Internal_IT

19.5

6

8

ICC_RDurkin

19

6

7

marcadamcarter

18.5

5

9

sstranger

18.5

5

9

james seatter

18.5

6

11

Mr grnnnx

17.67

5

8

Trevor Hayman

17.17

5

9

Jason Scott

17

4

8

Tomek Izydorczyk

15.83

4

8

Jeff Patton

15.75

4

10

Michael Moore

15

4

7

Brentos

15

5

7

Stijn Callebaut

15

6

7

Kirk Cessac

14.5

4

6

Martijn Haverhoek

14

3

5

UGSING_MattHitchcock

14

4

8

Dustin Hedges

14

5

6

Calle E

13.33

4

8

Vivien Schlottmann

13

4

4

jeffrey yao

12.67

3

6

resolver101

12.5

4

5

Michael Topal

12

4

6

Clayton Firth

12

4

4

Tom Parker

11.83

3

7

ScripterJT

11.5

3

6

Paul Iddon

11

3

4

Brent Challis

11

3

5

Paul Cunningham

10.67

3

6

J Skiba

10.5

3

5

Sean Decker

10

3

5

jillwi

9

2

5

T-Bone

9

2

3

artnib

8.5

2

3

M Emek

8

2

2

DJ Grijalva

8

2

4

Dave Ackroyd @LearnPowerShell

8

3

6

Clinton Merritt

7.67

2

4

Kiss Tamás

7.67

2

5

Jason Lange

7.5

2

3

Max Lindström

7

2

6

AaronHoover

7

2

3

MsMiller

7

2

3

Carlos Nunez

6.67

2

5

PeetersOnlineNL

6.67

2

5

Frank Peter Schultze

6.5

2

3

Brad Blaylock

6.5

2

4

Kerry Boomsliter

6.5

2

3

Mathieu Boulard

6

2

2

Svartvoff

6

2

2

MattBoren

6

2

3

Jon Bryan

5.17

2

5

Dave Griffiths

5

1

2

Mark Weaver

5

1

2

Nico

5

1

1

Brian Carr

5

2

4

Dan Jakubczak

5

2

3

JeremiahC

5

2

3

David Blackmore

5

3

4

f2b95d1a805fd4f8623b0d70b6ed3a19

4.67

2

5

Brandon Bettle

4.5

2

4

Damon Brinkley

4.5

2

4

Anonimista

4

1

2

Cameron Ove

4

1

2

Jose Quinones

4

1

2

Warpig

4

1

2

Justin Sowa

4

1

2

Claudiu P

4

1

2

smoshea

4

1

2

Scripting Scott Saari

4

1

2

Tobias

4

1

2

Jimmy Mac

4

1

1

Fredrik Wall

4

2

7

Justin Stokes

4

2

3

Dan Richardson

3.67

1

3

Steelwing

3.67

1

3

MSFTW

3.67

1

3

herschelle

3.67

1

3

Ryan Schlagel

3.5

1

2

John Main

3.5

1

2

Chris Oswalt

3.5

1

2

Wolfgang Kais

3.5

1

2

PeterCS

3.5

1

2

Tony McGee

3.5

1

2

Clint Bergman

3.5

1

2

Wayne Gault

3.5

1

2

Yuriy Prikhodko

3.5

1

2

Greg Martin

3.5

1

2

PatrikL

3.5

1

2

jessekozloski

3.5

1

2

IJuan

3.5

1

2

BurntChimney

3.5

1

2

Chris Stewart

3.5

1

2

Oneill Cameron

3.5

1

2

Claus Søgaard

3.5

1

2

SassDawe

3.5

1

2

Joshua Fuente

3.5

1

2

Ryan Shafer

3.5

1

2

Miruu

3.5

1

2

ThoamsBiebl

3.5

1

2

MarkJohnson

3.5

1

2

Patrick Dorsch

3.5

1

2

Josh

3.33

1

3

Chris Brown

3

1

2

Jacques

3

1

2

kiran reddy

3

1

3

David Eilers

3

1

2

crownedjitter

3

1

2

Matthew Vidrine

3

1

2

Frank Migacz

3

1

2

Scripting Scott Saari

3

1

2

ofirey

3

1

2

Erin Huligan

3

1

2

Tom Moser

3

1

2

Robert de Britto

3

1

2

Gregg Britton

3

1

2

Greg Shay

3

1

2

ginno

3

1

2

Jiri Formacek

3

1

2

Jakob Bindslet

3

1

3

Zach M

3

1

2

Jason Milczek

3

2

3

Dan Lepine

2.5

1

2

James Tryand

2.5

1

2

dude9000

2.5

1

2

Chris Duck

2.5

1

2

Claudio Westerik

2.5

1

2

Perry Harris

2.5

1

2

Eddy Steenbergen

2.5

1

2

Will Steele

2

1

4

Nathan Cook - AU

2

1

2

Franck Malterre

2

1

2

Marcin Kowalczyk

2

1

2

845ebf71ea404155b02971a5b6e8bc8d

2

1

2

jcriswell

2

1

2

WizardX2

2

1

2

Seth L

2

1

1

Rob Dowell

1.5

1

2

El Ryan

1.5

1

2

Andrew

1.5

1

2

Jim Vierra

1.33

1

3

Brian T. Jackett

1

1

2

Joel Bennett ͦ᷈_ͦ᷉

1

1

1

Ákos Kinczel

1

1

2

Johan Åkerström

1

1

2

Hong

1

1

2

Valeriy Aksyonov

1

1

2

Bret Ridenour

1

1

1

a690f3730d067a5c07abee279e6b0e97

1

1

1

 

Viewing all 3333 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>