The “Hey, Scripting Guys!” blog has been retired. There are many useful posts in this blog, so we keep the blog here for historical reference. However, some information might be very outdated and many of the links might not work anymore.
New PowerShell content is being posted to the PowerShell Community blog where members of the community can create posts by submitting content in the GitHub repository.
Scripting Blog [archived]
Formerly known as the "Hey, Scripting Guy!" blog
Latest posts

PowerShell for Programmers: The Magic Switch!
Welcome back everyone, I'm trying out GitHub Gist for my code blocks this week. It lets you click and download them, as well as making them easy to edit. The downside is that I can't use my usual dark themed syntax highlighting. Let me know in the comments if you like gist or the old method better :) Switch statements in PowerShell are very cool, and by knowing some of the tricks it has in place it can save you a lot of time. Basic Syntax Let's start by taking a look at a basic switch statement. In C# you might write something like this: In PowerShell you could do this: Notice we don't use t...

PowerShell For Programmers: Strings, Quotes and Quirks
Welcome back everyone! This will be a short, but important entry for the guide. The difference between quote characters is something I’m asked about all the time. It is important to understand in PowerShell, but most of the time it probably won’t make a difference. TLDR: If you're just typing a value like "alg" then it doesn't matter, but if you have any special symbols you can see the difference. Single vs. Double Quotes We refer to single quotes as Literal Strings and double quotes as Expandable Strings. Both create the same datatype (system.string), but a double quote will expand any special charact...

PowerTip: Create new authentication keys for AzureRM Cognitive Services

Summary: Change the keys to authenticate to Azure RM Cognitive Services, by using Windows PowerShell. Hey, Scripting Guy! I created the keys for my Rest API. I know I can change them in the web portal, but is there a faster way of doing it through Windows PowerShell? There absolutely is! Just use the New-AzureRMCognitiveServicesAccountKey cmdlet to reset either Key1 or Key2 (or both). Here is an example, where we generate a new sequence for Key1: New-AzureRMCognitiveServicesAccountKey -ResourceGroup 'HSG' -Name 'Sample' -KeyName Key1

Windows PowerShell and the Azure Text-to-Speech Rest API (Part 1)

Summary: You can use Windows PowerShell to authenticate to the Microsoft Cognitive Services Text-to-Speech component through the Rest API. Q: Hey, Scripting Guy! I heard about the cool Microsoft Cognitive Services, and had heard they have a REST API. Does that mean I can use PowerShell to consume them? Could you show me how to authenticate to it? —SH A: Hello SH, I just love waking up and saying "YES YOU CAN!" when people ask "Can you do that with Windows PowerShell?" So… ahem…. "Yes you can!" For those who didn't know, Cognitive Services are hosted in the Azure cloud, and they allow you to many things eas...

PowerTip: Use PowerShell to read an RSS feed

Summary: “Hey, Scripting Guy!” shows you how to use Invoke-RestMethod to read a list of entries from an RSS feed. How can I use Windows PowerShell to see the list of articles from an RSS feed? Just use the Invoke-RestMethod and provide the full path to the link to the RSS feed. Here is an example: Invoke-RestMethod -Uri 'https://blogs.technet.microsoft.com/heyscriptingguy/rss.aspx

PowerShell and the REST API for the IT pro

Summary: This post provides a quick introduction to what the REST API is, and how it applies to Windows PowerShell. Q: Hey, Scripting Guy! I can see there is this cool cmdlet called Invoke-RestMethod. I've been told REST API's are all around, and this allows me to consume that data. Could you give me a hand getting started? —SH A: Hello SH, Glad to help out! I remember hearing about REST APIs the first time, thinking they might be a way to take a nap at work. Was I wrong on that one! What a "REST API" is at the most BASIC level is really just a very fancy web Endpoint. You could, if you were really creative, t...

PowerShell for Programmers: How to write a function the right way
Just like I mentioned in my first post, PowerShell supports a lot of stuff that makes it pretty easy to dive in and get stuff running. The following two examples are supported in PowerShell, but not something you should really be doing for any reusable tool set. Putting your parameters (arguments) next to the function name in parenthesis is pretty standard in most languages, but in PowerShell it will limit your functionality. Similarly, $args will stop working for you if you add some of those more useful features, but I’ll show you a way to mimic the functionality on your own later. So, how should you b...

PowerShell for Programmers: What happened to my operators?
Operators are one of the most frustrating things about learning PowerShell if you’re coming from just about any other language in existence. Operators like ==, <=, !=. etc. are almost ubiquitous in programming, but none of them are supported in PowerShell. This can lead to some pretty frustrating errors with things like If statements. You might see: In PowerShell we are still going to have all these operators, they are just going to look different, using dashes and vaguely resembling parameters. I wondered the reason behind this myself for a while, and made a pretty inaccurate guess, but...

PowerShell for Programmers: Basic Syntax – Variables, Objects, and Data Types
Variables Variables in PowerShell are going to be a bit different than they are for you in most languages. To start out the conversation, the basic way to create a variable is just by using a “$” and an “=”, but there are cmdlets and other ways to generate them. Objects Objects are going to work how they do most places. Dot notation lets us dig into their properties and methods. If you want to see your object’s members, we have several options: 1. Get-Member: you’ll notice the definitions look a lot like you’re used to in C-based lang...