Year after year I see many people who were old-fashioned mouse clickers adopting

So what is the best way of testing your progress than a tricky PowerShell contest and possibly winning a prize?

Let me announce then the

**PowerShell**and thus the average skill level is rising. At the same time, pushed by the arrival of DevOps, a lot of people who are already pretty confident with code are coming to join the ever-growing community of IT professionals that use PowerShell.So what is the best way of testing your progress than a tricky PowerShell contest and possibly winning a prize?

Let me announce then the

**third edition of the PowerShell Oneliner Contest**:
Before I announce the three tasks you will have to cope with, let me remind you of the spirit of this game:

- this must be a
**unique learning experience**, where solutions posted from experienced scripters will benefit the whole community once they are made public - novice scripters will have to show a lot of
**persistence**in order to get solutions that work, respect the rules and be creative **having fun**is of paramount importance while bending the command line in a creative way

**GENERAL RULES**

- The contest is split into three tasks of increasing difficulty
- Each task consists of a simple scenario for which you have to produce the shortest possible oneliner solution
- You can use every PowerShell version, just state in the comment which version you tested it with
- No semi-colons
- Backticks are accepted for readability
- To submit your entry, create a
**secret**Gist for each task solution and post the URL for the Gist as a comment to this blog article - Submitting an entry that is a public Gist will automatically disqualify the entry and participant
- Sign your comments so that I know who's who and so that I can get in touch with the winner
- Entries (comments) will not be made public until after the submission deadline
- The first person to produce the shortest working solutions to a task will get 1 point, the second 2 points, the third 3 points and so on
- The person with the lowest total score over the three mandatory tasks will be the winner
- The contest will run for nine days beginning today until November 21st 12:00 noon (GMT)
- The winner will be announced on Friday, November 24th on this blog
- I'll be the only judge

**TASK 1: MANIPULATING OUTPUT**

Windows Management Instrumentation is an incredibly useful technology for exposing system information. Being able to interact with it from PowerShell is one the first things we all learn. Your first task is to write the shortest possible oneliner that extracts the UNC path of all the local shares from the Win32_Share class.

Expected output:

Expected output:

\\srv01\ADMIN$ \\srv01\C$ \\srv01\E$ \\srv01\F$ \\srv01\IPC$The use of Win32_Share class is mandatory.

**TASK 2: MANDELBROT JOKE**

I still remember the first time I saw a computer-generated fractal (it was a Barnsley fern), and have always been impressed by those patterns that repeat and repeat again. What I did learn recently is that the '

*fractal*' term was invented by a legendary Polish mathematician, Benoit Mandelbrot, who added a B. in the middle of his name: supposedly he intended his middle B. to recursively mean Benoit B. Mandelbrot, thereby including a fractal (his mathematical discovery) in his own name.
Your mission is to write the shortest possible oneliner that answers this question

$question = 'What is the middle name of Benoit B. Mandelbrot?'by returning

The B in Benoit B. Mandelbrot stands for Benoit B. Mandelbrot.Reuse of

*$question*variable is mandatory.**TASK 3: TEXT MINING**

There's a lot of hype today around data mining techniques and therefore I want you to see how good you are at using PowerShell for a special kind of task. Given the following two text variables

$t1 = "I really like scripting with PowerShell" $t2 = "PowerShell is a really really nice scripting language"write a oneliner that is capable of determining text likeness using Cosine Similarity and returns

0.516397779494322The returned value must be 1 if

*$t1*and

*$t2*are identical vectors (same words) and 0 if

*$t1*and

*$t2*have no words in common.

The comparison must be case insensitive, meaning that PowerShell and powershell are the same word. The string must be split at any non-word character and only unique elements of the resulting collection are compared.

The oneliner should work against any other pair of text variables, for instance

$t1 = "Unless you work hard, you won’t win." $t2 = "You must work hard. Otherwise, you won’t win."must return

0.870388279778489

**SOLUTION TESTING**

Being able to test your solution and see that it respects the rules is of paramount importance before submitting it. If you are taking part in this contest I suppose you must not be new to Pester. Fellow MVP Jakub Jares (@nohwnd) was kind enough to provide a

**solution validation tool**based on his

*Assert*module:

https://github.com/nohwnd/PowershellContest2017

Use the three provided test files (one per task) as stated in the Readme.md instruction file.

A word of notice: using those tests is

**not mandatory**, but my opinion is that we should all be

**continuously learning**, so if you are

**new to GitHub and to Pester**, I suggest you seize the occasion to learn something useful. You'll just be doing yourself a favor if you use Pester to unit test your oneliners, because human error can always happen and it's a pity if you spend a lot of time providing an answer that does not actually work.

If you are interested in Jakub's Assert module, you can find it here:

**THE PRIZE**

Yes, there's a prize! Fellow MVP Mike F Robbins will donate one copy of The No-Nonsense Beginner’s Guide to PowerShell ebook for the winner of the contest. Thanks in advance to Mike for being always so keen to give his contribution to this kind of initiative. His book is one of the best around, as I explained in a previous post.

As a

**bonus**, and if the winner agrees, he/she will intervene as a

**guest blogger**on this blog and will explain how to solve this kind of PowerShell riddle.

If you want to spread the word about this PowerShell contest, feel free to twit about it. You can use the hashtags

**#poshcontest2017**and

**#powershell**so that other competitors can share their thoughts (not the solutions of course!).

Have fun!

**UPDATE 24th Nov: We have a winner! Check it out here.**

https://gist.github.com/anonymous/e06a4232d264ec493d279e55188ac601

ReplyDeleteFor the first one :D

Hugues BOUTET

Another one shorter 48 Chars

ReplyDeletehttps://gist.github.com/anonymous/508e837bc5b599baf5bcf669c54c5bd0

Hugues BOUTET

https://gist.github.com/jwizzle29/023594d9bf254743c850ac558dc197a8

ReplyDeletehttps://gist.github.com/KevinMarquette/0a6ff02bb9bc0131a71bb395ed6ea554

ReplyDeleteTask 1, KevinMarquette

Task one.

ReplyDeletehttps://gist.github.com/Bigj8705/2af740b9846b69080a6061e0ee5d9b13

Jeffery Hayes

@DisabledJeff

1st task was easy enough to do on a short break. I'll have to do some research for 2 & 3.

ReplyDeletehttps://gist.github.com/mjnbrn/fbaad17fcf0040ab477f2da2e85b491d

--mjnbrn

Task 1 - PowerShell Version 3.0

ReplyDeletehttps://gist.github.com/jeremytbrun/63a7fbcf93b03b6e2a1819ab68fc976c

Task #2 - PowerShell Version 3.0

ReplyDeletehttps://gist.github.com/jeremytbrun/4ef6786081eee77cae495e730dc31fbe

https://gist.github.com/KevinMarquette/47628f1a15991817d33c5e246d30936e

ReplyDelete#task 2

https://gist.github.com/pwsh/7560688f1ab40196717b5ec3b2e29511

ReplyDeleteTASK 1 - Matthew Dowst (Matthew.Dowst@catapultsystems.com)

ReplyDeletehttps://gist.github.com/mdowst/66e0a59cff65dce86fad162c01a679d2

TASK 2 - Matthew Dowst

ReplyDeletehttps://gist.github.com/mdowst/162f2db279a5a7502525391943f81a36

Todd Schertzing

ReplyDeletetschertzing@rigelksecurity.com

Task 1

https://gist.github.com/reap-/b88b327a4a77a8bca11ca1977e0ef9b5

Todd Schertzing

ReplyDeletetschertzing@rigelksecurity.com

task 1 - it may have submitted already, sorry if it did

https://gist.github.com/reap-/b88b327a4a77a8bca11ca1977e0ef9b5

https://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

ReplyDelete- Nathan Ziehnert (@theznerd)

Oops - one change to reduce char count on task 3...

ReplyDeletehttps://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

- Nathan Ziehnert (@theznerd)

1 - https://gist.github.com/HumanEquivalentUnit/0bc465bbf570e717922888d3bd7d0670

ReplyDelete2 - https://gist.github.com/HumanEquivalentUnit/bc364d99d2e42f3a4b2e3cb75f230e59

3 - https://gist.github.com/HumanEquivalentUnit/529556404b7f9a6a55c3e4e4e0aad02a

/u/ka-splam

Entry for task 1: https://gist.github.com/tallpaulf/1abb575ca0237c25dabfd1be2a9316c2

ReplyDeletePaul Farrington.

Solution for task 2: https://gist.github.com/tallpaulf/fdfef9dc3b9e36b5fb5236d6e9af3a92

ReplyDeleteTested with PS 3.0

Paul Farrington.

Task1

ReplyDeletehttps://gist.github.com/JockserTHD/21d40a5d4bcced792878a409f200ccaf

Task1

ReplyDeletehttps://gist.github.com/JockserTHD/21d40a5d4bcced792878a409f200ccaf

Task 2

ReplyDeletehttps://gist.github.com/JockserTHD/be8db56804097230270f88af7b899050

I suppose one more update to my entry for task 3...

ReplyDeletehttps://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

- Nathan Ziehnert (@theznerd)

https://gist.github.com/SimonWahlin/5793164ce61a76eb72f37f5f2a9650fa

ReplyDeleteAnd an update to task 1:

ReplyDeletehttps://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

- Nathan Ziehnert (@theznerd)

https://gist.github.com/SimonWahlin/67982b0385b3bcef99425fa2f34d13c2

ReplyDeleteEntry for Task 1

ReplyDeletehttps://gist.github.com/Windos/d3aea2c4d46a11718e2d80188b025232

Josh King (@WindosNZ)

Entry for Task 2

ReplyDeletehttps://gist.github.com/Windos/9a107ff82bc636a8acdb425730d8f08c

Josh King (@WindosNZ)

Task 3:

ReplyDeletehttps://gist.github.com/SimonWahlin/09520ce774d8b41dedcd775ce1d5328c

Here are my entries:

ReplyDeleteTask 1 (shares): https://gist.github.com/briantist/d57b8b67d0ecbb94b8098c628e2e0531

Task 2 (mandelbrot): https://gist.github.com/briantist/cc4c12577f84e30b239a63fb42554705

Task 3 (mining): https://gist.github.com/briantist/634ad8c7fb4e6b30b1a58194ba31c150

You can get in touch with me via Twitter @BrianScholer

https://gist.github.com/PatheticFish/6500cd978e2c0de2a8098f885756f7bc

ReplyDeletePhew, okay, here's my entry for Task #3...

ReplyDeletehttps://gist.github.com/Windos/d8dc32cbf13dfb3bdf9c7097fbd2af45

~ Joshua King (@WindosNZ)

Task 1 - https://gist.github.com/nomadtales/8b399caa9c78e788283f0a6282742398

ReplyDeleteTask 2 - https://gist.github.com/nomadtales/149709d4582ee8ed12030b427a8a3c35

Task 3 - Still working on this one.

Reduced #3 by an additional number of characters. Provided two examples - one requires that the $x,y,z variables be cleaned between runs of the command which I think doesn't meet the criteria of the contest.

ReplyDeletehttps://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

- Nathan Ziehnert (@TheZNerd)

Well... I found out where we differed in task three... this should be my final submission... unless I find something else super creative...

ReplyDeletehttps://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

- Nathan Ziehnert (@theznerd)

I have updated solutions for Task 2 (mandelbrot) and Task 3 (mining):

ReplyDeleteTask 2: https://gist.github.com/briantist/cc4c12577f84e30b239a63fb42554705

Task 3: https://gist.github.com/briantist/634ad8c7fb4e6b30b1a58194ba31c150

- Brian (Twitter @BrianScholer)

Task 2 (mandelbrot) gist updated: https://gist.github.com/briantist/cc4c12577f84e30b239a63fb42554705

ReplyDelete- Brian (Twitter: @BrianScholer)

Task2:

ReplyDeletehttps://gist.github.com/SimonWahlin/5793164ce61a76eb72f37f5f2a9650fa

Task3:

ReplyDeletehttps://gist.github.com/SimonWahlin/09520ce774d8b41dedcd775ce1d5328c

Task2:

ReplyDeletehttps://gist.github.com/SimonWahlin/5793164ce61a76eb72f37f5f2a9650fa

OK, not really happy with solutions, but also no time to make them better...

ReplyDeleteTask 1: https://gist.github.com/bielawb/8dfd09c796fb1a240720dc7acb2b8573

Task 2: https://gist.github.com/bielawb/2c55761487414069aaeeb6a187f3350b

Task 3: https://gist.github.com/bielawb/39108cd77e0330d2ae312bf107c18d89

3rd one in particular was just "get it to work" - no effort done to make it shorter. Oh well, life happened... ;)

And another update to #3... didn't cross my mind that -unique could be shortened to -u: https://gist.github.com/theznerd/1b02ee39ed72cac6553090a3167b5de8

ReplyDelete- Nathan Ziehnert (@theznerd)