Weekend Hack - New-Blogpost.ps1

I wanted to create a simple function that can be called quickly from my blog repository to generate a new blog post markdown file for this Github Pages Jekyll site. It also gave me a reason to try and use System.Text.StringBuilder. It seems like a nice way to build multi-line strings.

By default, the cmd assumes you want your blogs under _posts but if you are keeping them in a different location you can specify the path using -path. If the path doesn’t exist it will fail to run. If you do not provide a date, then the current date is used. However, you can provide a custom date by using the -date param. You can also provide some basic content using the -content param which will appear under the front matter of the markdown file. Lastly, you can tell the cmd that you want to open the file it creates in VS Code by using the -openwithcode flag. The cmd outputs an object using Get-ChildItem in case you want to pipe it out into some other command after you generate the post.

I might also configure a task in VS Code in the future that can call this function for you, but I’m not sure yet if that’s a good use of Tasks. File that under “Things I need to research”.

Next, I think it would be interesting to create some scripts that can rename a Blog post, change the date of a blog post, or a cmd that can archive blogs after a specific date. Also part of me wonders what an automated blog would look like. What kind of content could I systematically generate and then output and commit to GitHub?

Anyway, enjoy!

Printer Dashboard Pt 1 - Getting the Data

Credit: Max Wheeler

Everyone hates printers for one reason or another. Some of us are unfortunate enough to not only have to manage the technical side of printers, but also the mundane side of printers: Restocking Toner.

After a short time of manually checking in on printer toner levels, I decided there had to be a better way. We use Papercut for doing all kinds of printer management, but one thing it seemed to lack was a straightforward overview of toner across all your printers.

So I started doing some research and figured PaperCut must be getting the toner information via SNMP. After some reading, I found there is a Com Object that can be used to make SNMP calls, which can be used against printers. After much tinkering, I had a script that could pull printers from our print server, and loop through them making SNMP calls for toner levels.

SNMP Is a magical nightmare of non-standardization, and some manufacturers are better about getting you the information you need vs others. Some places, like Ricoh, keep their SNMP OID information behind a paywall. So I basically got lucky with the HP printers I manage. However, that’s not to say its simple or makes sense, as you can clearly see above.

When all is said and done, we convert the array to JSON and output it to a file:

ConvertTo-Json -InputObject $Printers -Depth 4 | Out-File -FilePath $DataPath

Getting the data is honestly the hardest part. I’ll create a follow up post soon that will cover turning that data in to a dashboard using UD.