Our March 2016 puzzle comes from Carlo Mancini. We’re actively interested in receiving Scripting Games puzzles from members of the community – submit yours, along with an official solution, to us at admin@ via email!
Instructions
The Scripting Games are a monthly puzzle. We publish puzzles the first Saturday of each month, along with solutions and commentary for the previous month’s puzzle. You can find them all at https://powershell.org/category/announcements/scripting-games/. Many puzzles will include optional challenges, that you can use to really push your skills.
To participate, add your solution to a public Gist (http://gist.github.com; you’ll need a free GitHub account, which all PowerShellers should have anyway). After creating your public Gist, just copy the Gist URL from your browser window and paste it, by itself, as a comment of this post. Only post one entry per person. However, remember that you can always go back and edit your Gist. We’ll always pull the most recent one when we display it, so there’s no need to post multiple entries if you want to make an edit. Just edit the original Gist and we’ll see your changes shortly.
Don’t forget the main rules and purpose of these monthly puzzles, including the fact that you won’t receive individual scoring or commentary on your entry.
User groups are encouraged to work together on the monthly puzzles. User group leaders should submit their group’s best entry to Ed Wilson, the Scripting Guy, via e-mail, prior to the third Saturday of the month. On the last Saturday of the month, Ed will post his favorite, along with commentary and excerpts from noteworthy entries. The user group with the most “favorite” entries of the year will win a grand prize from PowerShell.org.
Our Puzzle
Our Puzzle this month comes in a “Beginner” and “Advanced” variety. Indicate in a code comment which one you’re shooting for. And, you’re welcome to submit one entry apiece for Beginner and Advanced, if you like. These are a bit tricky – be sure to read carefully!
There’s a ZIP file with some sample filenames to help you practice and test your solution – this is applicable to both versions of the puzzle:
FileShare
Diacritics: The Beginner Version
You are a server administrator for an international company with four branch back-offices in Western Europe (France, Norway, Italy and Germany). People at these sites store their files (invoices, receipts, customer complaints, as well as internal documents) on a central file server located in the United States.
Since these back-office people have keyboards with a different layout from English QWERTY, they are able to save files with diacritical marks in their names on your central file server.
It seems that your corporate backup routine has problems with these files and your backup tools hangs.
Your boss has tasked you with finding precisely what kind of filenames interfere with the backup routine. After some time spent investigating the Unicode standard, you discover that this is a common problem in these European countries, and you find out that the culprits are, the ß used in German, the å, æ, ø used in Nordic languages, the é, é, ì and ò used in Italian, the ç used in French and, in general, all letters which are part of the Latin-1 Supplement character block.
Unhappy with the situation, your boss has asked you to run a script against your file server to identify all the files whose names have letters (not symbols nor numbers) in that character block and return the following information:
• The name of the file
• The containing folder
• The time of creation
• The date of the last modification
• The size of the file
An acceptable output for this task is shown in the following image.
Design Points
· Do not return files with other Latin symbols or numbers (like ©, ¼, ½, ÷) in their names.
· Assume that the appropriate ports are opened on your file server.
· Assume that Powershell Remoting is enabled on your file server.
· Use the simplest command that will work and feel free to write a one-liner if you able to.
· Display the output to the screen; you do not need to write to a text file.
Diacritics: The Advanced Version
Thanks to your reputation of Powershell guru, you have been hired by a fast growing international company with four branch back-offices in Western Europe (France, Norway, Italy and Germany). People at these sites store their files (invoices, receipts, customer complaints, as well as internal documents) on a central file server located in the United States.
Since these back-office people have keyboards with a different layout from English QWERTY, they are able to save files with diacritical marks in their names on your central file server.
It seems that your corporate backup routine has problems with these files and your backup tools hangs.
Your boss has tasked you with finding what kind of filenames interfere with the backup routine. After some time spent investigating the Unicode standard, you discover that this is a common problem in these European countries, and you find out that the culprits are, the ß used in German, the å, æ, ø used in Nordic languages, the é, é, ì and ò used in Italian, the ç used in French and, in general, all letters which are part of the Latin-1 Supplement character block.
Unhappy with that situation, and confident with your Powershell skills, your boss has asked you to setup a scheduled task that runs every Saturday night on your central file server which call a function that extracts a list of all the filenames which have letters (not symbols nor numbers) in that character block and send them to him by e-mail.
The e-mail must include the following information:
• The name of the file
• The containing folder
• The time of creation
• The date of the last modification
• The size of the file
The e-mail should be sent every two weeks on Saturday 11PM.
An acceptable output for this task is shown in the following images.
Design Points
- Your boss says you should provide two scripts:
- One which leverages Powershell Remoting to create the Scheduled task on the file server with the appropriate job trigger. Your boss challenges you to this to be a one-liner.
- One that contains the Get-Diacritic function that identifies the filenames with diacritic marks and e-mails the report.
- The function Get-Diacritic must generate a CSV file containing the mentioned information. The CSV file should by default be named yyyyMMdd_FileNamesWithDiacritics.csv (where yyyyMMdd represents the current year, month and day) and be stored in the system temp folder.
- No CSV report must be generated if the count of filenames with diacritic marks is null.
- The size of the retrieved files should be presented in a readable format followed by the most appropriate unit (i.e. 1.2MB, or 500Kb).
- You can assume that you have the required permissions to remotely access the File Server.
- Appropriate parameter validation and error handling must be put in place.
About the author of this scenario:
Carlo Mancini has been working as a system administrator for over 15 years and on PowerShell since its first release in 2007.
He is one of the winners of the 2013 PowerShell Scripting Games and is currently employed by one of the largest European IT companies where he is in charge of maintaining and administering both the physical and virtual architecture.
Carlo is also a technical speaker of renown at conferences around Europe and was awarded with the Microsoft MVP Award for Powershell in 2013 and 2014.
He is involved on many technical forums as well as on his blog, happysysadm.com.
https://gist.github.com/jaywryan/22d880a3e2ca73b179e8
The problem states
I did not format my question correctly (and there is no way to edit a comment):
The problem states …and, in general, all letters which are part of the Latin-1 Supplement character block however, the output you have shown does not include the file “¼ofthetotälits.txt”, which contains the letter ä (U+00E4). Do you mean to exclude all files that contain other Latin numbers or symbols, even if they do contain letters that meet the criteria?
Derek, that’s just part of the output. The file named “¼ofthetotälits.txt” has to be on the list (check the last image in the advanced scenrario, you’ll find it there).
Good luck!
Carlo
https://gist.github.com/derekables/47254943fb4c33b5b571
Thanks to Carlo and the organizers! This was pretty fun.
https://gist.github.com/brianbunke/4e375f1f6fa3806b9df0
Thank you Carlo, this should do the job!
https://gist.github.com/derekables/16f55298cec6a9f7e623
Beginner Solution
https://gist.github.com/Stuart-Moore/a5147932905384e4c0e8
Advances Solution – Get-Diacritic function
https://gist.github.com/Stuart-Moore/bb9ff74933f682e0e665
Scheduling the above command
https://gist.github.com/Stuart-Moore/ff66d1121177e3dc64d0
https://gist.github.com/liampkemp/ba9483e51a80f7016ae7
^Beginner
https://gist.github.com/Windos/b61d97298976ea79b706
Hello, my solution of The Beginner Version is here:
https://gist.github.com/helu2016/
This was fun!
https://gist.github.com/helu2016/
https://gist.github.com/king3vbo/8366c3cf26529e34da08
https://gist.github.com/king3vbo/e74d4efe2b8d91676329
https://gist.github.com/jeffbuenting/6e47f34b305daf89c29d
One-liner, using regex character class subtraction to exclude the math symbols.
https://gist.github.com/ProgrammingWithHandGrenades/f5d34850b90639949fbb
Get-ChildItem -File -Force -Recurse |
Where-Object {$_.Name -match ‘[\u0083\u008A\u008C\u008E\u009A\u009C\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]’} |
Format-Table Name, Directory, @{L=”Creation Date”;E={$_.CreationTime}}, @{L=”Last Modification Date”;E={$_.LastWriteTime}}, @{L=”File Size”;E={$_.Length}}
https://gist.github.com/michaellee7/10bb550fd6102a27f291.js
https://gist.github.com/davops/48a1d830f4aef738c9cd
Beginner Version
One liner beginner version FTW!
Beginner and advanced version + task registration can be found at the address below. All use the CharUnicodeInfo class to avoid false positive.
https://gist.github.com/helu2016/4456125a8ad0aa8e5a1a
You can remove this comment, I stupidly pasted an gist address I was testing URLs with… Sorry.
One liner beginner version FTW!
Beginner and advanced version + task registration can be found below. All use the CharUnicodeInfo class to avoid false positives.
https://gist.github.com/XPlantefeve/5b9a668d87052724cc4d
BeginnerAdvancedCombined
https://gist.github.com/kvprasoon/e8146706a2873f815779/edit
https://gist.github.com/kvprasoon/e8146706a2873f815779
I never remember which link to post, so I’ll just post both.
This is for the Basic; I’ll do the Advanced later:
https://gist.github.com/poshcodebear/087892243b74aa2af750
Oops I think I posted the wrong link first time round.
gist.github.com/michaellee7/10bb550fd6102a27f291
Sorry still didn’t get it right Please try this link
https://gist.github.com/michaellee7/10bb550fd6102a27f291
[…] really put a brain-twister out for our March 2016 Puzzle. Also, as a note, we’re eagerly awaiting submissions of next month’s puzzle, so […]
https://gist.github.com/KirillPashkov/59a266b2195f9863da0483caf23969ab