I went to PowerShell Saturday #10 at University of South Florida today. There was a great turnout and Blain Barton did a great job putting this together. I wanted to post a few of the things I learned today to pay it forward. Big shout out for Will Murphy and The Scripting Guy Ed Wilson for very enjoyable and informational presentations.

Will Murphy gave a presentation on Azure ARM templates. He chose to demo a template that creates a PaaS instance in Azure running a NAMI instance of WordPress. As Azure matures it become apparent that we will perform the bulk of our configurations via JSON templates and fill in the gaps with PS. I was pleasantly surprised to learn that you can use an ARM JSON template to create a new environment and then use the same template to make changes to that environment. Azure will omit the configurations that already exist and implement only the new. This allows your configurations to remain repeatable and consistent especially with DSC. Want to make a change? Add it to your JSON template and execute against your Resource Group. The change is made and the configuration is now ensured to be in every environment created with the template.

Ed Wilson was nice enough to share some good features that shipped with PowerShell version 5.0. The “get-clipboard” cmdlet is very useful when need to save to and retrieve from the clipboard. Pipe contents into get-clipboard as needed. “New-TemporaryFile” is a good cmdlet to create a temp file that you can use to store output. Now, lets say you are writing a script that is saving data to a file. Very rarely do you get the script correct on the first try. Most of the time you’re writing to the file, checking the file, deleting the file and repeating until done correctly. You can write the code below that will open the file in notepad and pipe the output to “out-null”. What this does is stop the script from processing until notepad is closed. So, notepad opens, you read the contents and then close notepad. Then the next line if the script executes and deletes the file.

notepad $tmp.Fullname | out-null
remove-item $tmp.Fullname -force

Very nice for repetitive iterations while honing in on the correct solution.

Here is a new feature that is pretty cool. Especially if you dislike using regex. Let’s say you have the following data set:
“Mu Han”, “Jim Hance”, “David Ahs”, “Kim Akers” | convert-string -example “Ed Wilson=Wilson, E.”.

Here is your output:
Han, M.
Hance, J.
Ahs, D.
Akers K.

Here is a link the the Scripting Guy post regarding convert-string. You’ll need to upgrade to Windows 10 or install Windows Management Framework 5.0 if you’re still using 7.

https://blogs.technet.microsoft.com/heyscriptingguy/2015/08/17/use-the-powershell-5-convert-string-cmdlet/

 

Until,
Pete

Leave a Reply