A lot of time has passed since I have organized a PowerShell oneliner contest. So when I saw the post by fellow MVP and scripting champion Mike F Robbins on a PowerShell Function to Determine Available Drive Letters, I thought that it could be fun to organize a contest to see who can manage to write the shortest possible oneliner that achieves the same result as Mike's function.
As you can see reading his blogpost, the function accepts parameters such as -Random, to return one or more available drive letters at random, or -All, to return all the available drive letters. It also allows you to exclude some letters from the match (A, B, C, D, E, F and Z) by means of a -ExcludeDriveLetter parameter.
Now, for this specific contest, what I want to get in a comment to this post is:
- a oneliner (meaning in particular no semi-colon) that
- returns one and only one random available drive letter on the system where it runs
- with the exception of A-F and Z
- whose object type is a System.String (I'll check this Get-Member)
- and whose formatting is, say, G: or h: (case doesn't matter, we are on Windows)
- aliases are mandatory, meaning that you can't use a cmdlet unless it has an alias
- backticks are accepted for readability
- you can use every PowerShell version, including 5.1, just state in the comment what version you tested it with
- should you find a shorter oneliner to solve a task you are allowed to post additional comments (just remember to sign your comments so that I know who's who and so that I can get in touch with the winner)
A few more rules:
- Entries (comments) will not be made public until after the submission deadline.
- The first person to produce the shortest working solutions to the task wins.
- The winner will be announced on Friday, November 4th on this blog.
- I'll be the only judge.
If you want to spread the word about this PowerShell contest, feel free to twit about it. You can use the hashtags #poshcontest2016 and #powershell so that other competitors can share their thoughts (not the solutions of course!).