Scripting Blog [archived]

Formerly known as the "Hey, Scripting Guy!" blog

Latest posts

PowerTip: Get all your local certificates by using PowerShell
May 9, 2018
Post comments count 0
Post likes count 0

PowerTip: Get all your local certificates by using PowerShell

Doctor Scripto
Doctor Scripto

How can I use Windows PowerShell to enumerate all certificates on my Windows computer?

Get certificate info into a CSV by using PowerShell
May 9, 2018
Post comments count 3
Post likes count 0

Get certificate info into a CSV by using PowerShell

Doctor Scripto
Doctor Scripto

Summary: Certificate management is always challenging. Let’s explore how to use PowerShell to export local certificate information to a comma-separated values (CSV) file on Windows 7 (or later) computers. Q: Hey, Scripting Guy! How can I get all my certificate info into a CSV on my Windows computers? —SH A: Hello SH, Patrick Mercier here, with my first “Hey, Scripting Guy!” post. This question has come up at multiple customer sites, as they plan a new PKI infrastructure or a revamp of their current one! There’s tons of resources on using PowerShell for querying certificates, but questions around finding exp...

Grabbing Excel (XLSX) values with PowerShell
May 8, 2018
Post comments count 0
Post likes count 1

Grabbing Excel (XLSX) values with PowerShell

Kory Thacher
Kory Thacher

The Goal: Import data from XLSX files conveniently like import-csv lets you do with simpler data. The preamble: Excel is a mainstay of the business world at this point, which means a lot of the data you might have to work with will come at you as an XLSX file or need to be one. This can be a bit annoying when scripting. If we're just working in PowerShell-land and we can choose to use simple CSV data we have the handy import-csv and export-csv cmdlets, and those CSV files can open up in excel just fine. However, when we are forced to work with XLSX files it can lead to headaches. If you search around ...

Doing More With Functions: Comment-Based Help
Apr 24, 2018
Post comments count 0
Post likes count 0

Doing More With Functions: Comment-Based Help

Kory Thacher
Kory Thacher

I just wanted to throw together a post highlighting how cool and easy it is to add help data to your own Functions and scripts. The help data gets added via comments. For functions the help data can go in three places: For scripts we just put it at the top of your script before you type the param() statement, or at the bottom, but the bottom will mess with code signing. Syntax just involves using a dot before the help keyword and then typing the help you want for it on the next line: Here is a list of all the keywords I found and short descriptions of them: For the most part, I recomm...

Inserting new elements into XML files
Apr 10, 2018
Post comments count 0
Post likes count 0

Inserting new elements into XML files

Kory Thacher
Kory Thacher

The Goal: Insert nodes into a specific place in XML config files The Motivation: I had a coworker a while back working with App Fabric. He needed to insert a particular chunk of XML into a specific spot inside of the config file. This had to be done on a bunch of different machines, but the kicker was that the config files might look different on all of them. We knew the node that needed to come before our new node, but that might be in a different spot in each file. When the configSections node ended ( </configSections> ) we needed to insert: This is the perfect place for PowerShell auto...

Introducing the DscLcm utility for PowerShell
Mar 30, 2018
Post comments count 0
Post likes count 0

Introducing the DscLcm utility for PowerShell

Doctor Scripto
Doctor Scripto

Summary: Desired State Configuration is a great deployment tool to meet your organization’s infrastructure-as-code goals. I recently came across a situation for a project that uses the Push Service (as opposed to the Pull Service). It required me to be able to apply a new partial configuration to a node, without any knowledge of what partial configurations were already in place. This led to the development of the DscLcm module, which solved that problem for my team. DscLcm module The DscLcm PowerShell module is a utility that interacts with the Local Configuration Manager (LCM) of a target machine. You don’t have...

Doing More With Functions: Taking Parameters on the Pipe
Mar 27, 2018
Post comments count 0
Post likes count 1

Doing More With Functions: Taking Parameters on the Pipe

Kory Thacher
Kory Thacher

In an earlier post, I showed you how you could use the [parameter(mandatory)] attribute to force your parameters to behave  a bit more like you'd expect from other languages. We also have a bunch of other useful attributes we can use on our parameters to enable cool features. Pipelineing The pipe might feel pretty magical to you in PowerShell, as it just seems to work with our built in cmdlets. You can add this same kind of functionality to your own tools, and we give you two options to do so. First of all, here is what happens if you don't use this attribute: Pipeline By Value When we talk about stuff...

PowerTip: Build simple HTML with PowerShell
Mar 15, 2018
Post comments count 1
Post likes count 0

PowerTip: Build simple HTML with PowerShell

Doctor Scripto
Doctor Scripto

Summary: Here’s how to use the ConvertTo-HTML cmdlet to build basic HTML content.   Hey, Scripting Guy! Occasionally I need to build basic HTML documents. I heard there was a way to do that with Windows PowerShell.   There most certainly is! Just use the ConvertTo-HTML cmdlet to save the day! For example:                           $SampleDoc=@'                           This is a simple text Document in PowerShell                           That I am going to make into a Tiny web page                           :)                           '@                           ConvertTo-Html -InputObject $SampleDoc      ...

Windows PowerShell and the Text-to-Speech REST API (Part 2)
Mar 15, 2018
Post comments count 0
Post likes count 0

Windows PowerShell and the Text-to-Speech REST API (Part 2)

Doctor Scripto
Doctor Scripto

Summary: You can use Windows PowerShell to authenticate to the Text-to-Speech REST API. Q: Hey, Scripting Guy! I was reading up on the REST API for the Text-to-Speech component of Cognitive Services. I'm just starting to learn how to use REST and PowerShell. Could you spend a little bit of time and show me how to authenticate to the service? —SH A: Hello SH, Authentication is one of the biggest pieces you'll want to learn. Telling a system at the back end who you are, and knowing how to communicate with it, is very critical before you can do anything fun! Talking to the Text-to-Speech API is pretty easy onc...