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
PowerTip: Set the color of the progress bar with PowerShell
Summary: Use the $Host object to alter the color of the progress bar in PowerShell. I was curious if there’s a way to change the color of the progress bar in PowerShell. Do you know how this could be done? Glad you asked! You can do this by altering the values for ProgressBackGroundColor and ProgressForegroundColor under $Host.PrivateData. To change to a bright green background with a black foreground, use the following code in PowerShell: $Host.PrivateData.ProgressBackgroundColor=’Green’ $Host.PrivateData.ProgressForegroundColor=’Black’
Build a hexadecimal clock in PowerShell – Part 4
Summary: Use PowerShell to navigate the neutral zone. Honorary Scripting Guy, Sean Kearney, is here today to continue forth (not COBOL nor even Visual BASIC) into our silly yet fun quest to build a hexadecimal clock by using the PowerShell console. It does seem silly, doesn’t it? Yet, consider some of the things that we’ve learned in PowerShell during our quest. So, although the quest seems silly, we have learned quite a bit. Actually, it's much like any quest. The goal isn’t the point. It’s what you learn or experience while getting there. Our next part is to figure out how to draw this silly thi...
PowerTip: Set a default value in a switch statement
Summary: Use the default field in switch statement to have an assumed value. I was playing with Select-String and would like to have it default to a value if none was trapped for. How can I do that? Just use the Default keyword, and you can have an assumed value in the script block. In the following example, the switch is listening for the $DogSeesSquirrel object. If no values match, it returns ‘Squirrel runs free’. { 'Back door' { $Response=’Bark!’} 'Couch' { $Response=’Growl a bit.’} 'Food bowl' { $Response=’Bark! Bark! Bark!’} Default { $Response=’Squirrel runs free’ } } My apologies to our little d...
Build a hexadecimal clock in PowerShell – Part 3
Summary: Use Select-String in PowerShell to identify data and match it to an array. Honorary Scripting Guy, Sean Kearney, is here today to play more with our funky, nerdy, cool hexadecimal clock. Yesterday we built out a small function named Get-HexTime to give us the current time that displays hex digits instead of decimal for hours, minutes, and seconds. One of our challenges is going to be matching up the individual hex digits to our positions in the array. We can step through the list of characters in HexTime with a pretty simple loop: $Hextime=Get-Hextime For ($Count=0; $Count -lt ($HexTime.Length); $Coun...
PowerTip: Use PowerShell to identify a leap year
Summary: Use PowerShell and Math to identify a leap year. Is there a way to use PowerShell to identify whether this year is a leap year? Actually there is! You can use a combination of Get-date to find out the year and the Modulus function in PowerShell. If the value is zero, the current year is a leap year!
Build a hexadecimal clock in PowerShell – Part 2
Summary: Manipulate string data from Get-Date in PowerShell. Honorary Scripting Guy, Sean Kearney, is here today to have a little more fun with our silly project to build a hexadecimal clock in the PowerShell console. Well, after all, who said scripting wasn’t allowed to be fun? That’s usually how I learn, by playing about! Yesterday, we defined a cool array of Here-Strings that contain all the characters that we’d like to display in our clock. Today, we’re going to access the properties of the current time and see how we could put that to use. The very first thing that we’ll need to do is pull up the date an...
PowerTip: Extend a string array in PowerShell
Summary: Use the built in features of PowerShell to easily add new Element to a string array. I created an array of strings in PowerShell, but I need to add to it. Is there a simple way to do this? Absolutely. Just use += to add an element to your string array. In the following example, we add a new element to the array that’s named $HSG
Build a hexadecimal clock in PowerShell – Part 1
Honorary Scripting Guy, Sean Kearney, is here today, and I’m going to sit down and have some fun this week. Today I was feeling a bit bored and, for some reason, the thought “hexadecimal clock” entered my head. Don’t ask why because I’m not quite sure about the “Why” part. But, it just did. Then, I sat down and thought, what’s involved? Really? As a script, from a pseudo-code standpoint, it’s pretty simple Only I wanted this to be…well…b-i-g. In my head, I wanted a clock as wide as my console. That started my head spinning. “Big letters. How can I draw big letters and numbers?” In the “old world” ...
PowerTip: Export Azure resource group as JSON by using PowerShell
Summary: Use the Azure Resource Manager cmdlets to export a resource group as a JSON configuration. I’ve heard that JSON is used to define features in Azure Resource Manager. Is there a way to export a resource group in JSON format? Just use the Export-AzureRMResourceGroup cmdlet and provide the resource group name. It will automatically save a JSON file that matches the resource group name in your current folder. Here is an example: