Just developed some scripts to assist blogging on my BlogSite. To do so I did some “Monkeys on a Typewriter Coding” using PowerShell. This site is a custom Jekyll-Markdown site. I wanted a couple of scripts to generate a new blog post using metadata obtained from command line parameters and a menu. I could have coded them in Jekyll but chose to do in it in PowerShell.

I have discussed the functionality of these scripts on another post here: This blog site construction-Latest. It has links to the code that will be reused here. On this page I want to focus upon the PowerShell functionality gleamed from searching the internet. The code has references to where hints or solutions to the functionality was found, much like a “Dear Diary”.

No. Script & Link Description
1 set-path.ps1 Sets the PowerShell prompt path to include the location of these scripts
2 jekyll-clean.ps1 Clean built site as well as some custom generated pages to do with categories and tags
3 new-post.ps1 Generate a templated new post as Markdown file with FrontMatter from supplied metadata
4 new-post-yml.ps1 Same as previous but uses Categories from sections.yml for Category selection menu

The following table lists some PowerShell functionality implemented (not in any particular order) in these scripts.
Browse through the scripts 2,3 and 4 (unless otherwise stated) to see how to implement the functionality and to read further:

PowerShell Functionality Comment
Check if a file exists e.g. if ( Test-Path $sections )
Parameters N.b. Need to be first in script.
Mandatory and Default Parameters See 3,4
Install a PowerShell Module (YML in this case) See 4
Check if a PowerShell module has been installed See 4
ConvertFrom YAML See 4
If .. Else  
For and Foreach Loops N.b. no Then
String.Format  
String.Replace $string.Replace(‘a’,’b’)
String Null or Empty test  
String Concatenation  
String length $string.Length
New Text File  
Text File Write to and Append  
Input TextFile to String See 4
Generate menu from a list See 4
Get Menu selection and use to get list item See 4
Split a list of tuples into two singular lists See 4
List length Use Count property
Convert string to int and viz  
Date string formatting See 3,4
Output to command terminal write-Output ‘string’
Comments Precede line with #
Present Working Directory Path $pwd.Path
Get and Set Environment Variables See 1
Append to Path locally See 1
Throw an error See 1
String split on a character See 1
Delete a folder See 1
Create a folder if it doesn’t exist See 1

 TopicSubtopic
  Next: > .NET Core on IoT
<  Prev:   .NET Core on IoT
This Category:Coding
  Next: >