PowerShell’s format operator

I just came across a tip at the Hey, Scripting Guy! Blog about grouping numbers and controlling the decimal places after the dot, that describes the use of the ToString method of the number (int) object. Since I prefer using PowerShell’s -f format operator for that, and it’s description in the PowerShell help topics (Get-Help…


Get and Set the machineKeys in machine.config

In an ASP.NET web application, if you use ViewState, Session, Forms authentication, or other encrypted and/or secured values, these values are encrypted and decrypted using a set of keys called decryptionKey and validationKey located in the machineKey element under the system.web section in the .NET’s machine.config file. Normally, these keys are automatically generated every time…


Get and Set the compilation debug flag in web.config

Since the main technology I support as a PFE is IIS, I often find myself writing scripts for IIS or ASP.NET management. For example, one of the first things I check when troubleshooting ASP.NET applications is the debug flag in the web.config. For this, I’ve written the following two example functions that use the accelerator…


PowerShell scripting best practices

For the past few years, I’ve picked up a several best practices for PowerShell scripting. Some of them are “borrowed” from Ed Wilson (aka the Microsoft Scripting Guy), Don Jones, and other PowerShell MVPs and PFEs @ Microsoft. Note: For more PowerShell best practices, check the PowerShellPracticeAndStyle github repository Start your scripts with a standard…


Dynamic ValidateSet in a Dynamic Parameter

A colleague of mine needed a way to have a parameter accept only a specific set of paths. I told him this can be accomplished easily with the ValidateSet decoration on the parameter, but he then explained that what the actually needed, is to have the set dynamically defined by the sub folders in the…


Get Excel data without Excel

In a specific scenario, I needed to be able to query an Excel file and get data from a worksheet but I didn’t (and couldn’t) have the Office suite (or even Excel only) installed on the machine. If the Excel file is and xlsx file (the new Microsoft Open XML Format since Excel 2007), you…


Set the Windows 7 user account picture

Not too long ago, I was asked if it's possible and how to set the Windows 7 user account picture (the one you see in the Start menu, and in the Lock screen) using PowerShell.There is no official documented way of doing it, but it can be accomplished quite easily using the SetUserTile static function…


Free PowerShell eBooks

last update: 2014/11/28 This (frequently updated) post contains links to useful and free PowerShell eBooks. If you have a suggestion for an eBook to be added to the list, please add a comment at the bottom of this post. The Altaro PowerShell Hyper-V Cookbook:http://www.altaro.com/assets/Altaro-PowerShell-Hyper-V-Cookbook.pdf Active Directory PowerShell Quick Reference:http://www.jonathanmedd.net/wp-content/uploads/2009/10/ADPowerShell_QuickReference.pdf WMI query language (WQL) via PowerShell:http://www.ravichaganti.com/blog/wp-content/plugins/download-monitor/download.php?id=25…


Useful PowerShell Modules

2016-03-10 update: Using WMF 5.0 or WMF 3.0/4.0 with the PackageManagement and PowerShellGet modules, you can search for and install PowerShell modules from the PowerShell Gallery using the Find-Module and Install-Module cmdlets. Therefore, I will not be updating this post anymore. This (frequently updated) post contains links to useful PowerShell Modules. If you have a…


Write-Host “Hello World”

Hello world. My name is Martin, and I’ve been working in the IT industry for over 15 years, last 3 at Microsoft as a Senior Premier Field Engineer. What does a Premier Field Engineer (PFE) do? Read all about it here. Anyway, in this blog, I’ll be posting PowerShell tips I collect from the field….