Category: PowerShell

PowerShell Version 2 Compatible Function to Determine Windows Firewall State

I recently had a need to perform some security auditing on an environment that still has some servers running PowerShell version 2 (PowerShell version 2 is deprecated). One of the things I needed to determine was whether or not the Windows firewall was enabled on each of the servers in the environment. Luckily, all of the servers at least had PowerShell remoting enabled. The PowerShell function shown in the previous code example is a wrapper for the Netsh.exe command. Read more [...]

Remotely cleanup log and temp files from your Windows based servers with PowerShell

Setting up a scheduled task or job on individual servers to cleanup log and temp files just doesn't scale very well because you have scheduled tasks or jobs setup on lots of individual servers that need to be maintained. Today it's this server and tomorrow it's two or three more. It's much easier to setup one scheduled task or job on a server that's designed for management to remotely cleanup the desired files on all of your servers. The following log and temp file cleanup script is provided as Read more [...]

Using Out-GridView to simplify selecting the region when managing Microsoft Azure with PowerShell

You've signed up for a Microsoft Azure account and you've installed the Azure Resource Manager PowerShell cmdlets on your computer. You login to Azure from PowerShell. You'll normally see most people use Login-AzureRmAccount, but that command is an alias (Login isn't an approved verb). Login to Azure and provide the account login information when prompted: Several of the cmdlets in Read more [...]

How to install Visual Studio Code and configure it as a replacement for the PowerShell ISE

If you follow me on Twitter, then I'm sure you're aware that I've been using nothing but VS Code (Visual Studio Code) as a replacement for the PowerShell ISE (Integrated Scripting Environment) for the past couple of weeks and while I had tried it in the past, I didn't previously think it was ready for prime time. That's now changed with all of the updates and work that has gone into it. From what I've found, it works fairly well flawlessly so I've created a short and simple video to help others Read more [...]

VS Code Rendering Problem in the PowerShell Integrated Terminal

I recently discovered a rendering problem in VS Code where pressing escape doesn't delete a multi-line command in the PowerShell integrated terminal. I created a video to report the problem and I thought I would share it here since the quality was less than optimal when sharing it on Twitter. Here's a link to my original tweet to David Wilson and here's a link to the GitHub issue that Max Trinidad has created. µ Read more [...]

PowerShell One-Liner to Audit Print Jobs on a Windows based Print Server

You've been tasked with auditing print jobs on your company's Windows based print server to determine who is wasting so much paper, toner, and causing excessive wear and tear on printers. No budget exists for this task and you need to have something to show by the end of the day. You would probably start off by searching the Internet, but most of the results you'll find to accomplish this task are over-complicated or simply don't work. Luckily this task can be accomplished with a PowerShell one-liner. Read more [...]

PowerShell PackageManagement and PowerShellGet Module Changes in Windows 10 Version 1511, 1607, and 1703

Recently, I reloaded my computer and noticed a problem when I tried to install the latest version of the Pester PowerShell module using PowerShellGet. I loaded Windows 10 version 1703 (the creators update) which has PowerShell version 5.1 installed by default: Pester version 3.4.0 ships with both Windows 10 version 1607 and 1703. Both of these versions of Windows and/or PowerShell seem to work differently than previous versions when updating and/or installing Read more [...]

Presenting PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell this weekend at SQL Saturday Baton Rouge

Late last night I received an email about a session being cancelled at SQL Saturday #628 in Baton Rouge which is scheduled for tomorrow, Saturday, July 29th. I'll be presenting my PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell session in that time slot which is the first session of the day in the PowerShell track, beginning at 9:15am. I've presented this session a couple of times this year at other events and I've tweaked it each time based on the feedback I've received. Read more [...]

Operational Validation Testing of SQL Server with PowerShell and Pester this weekend at SQL Saturday Baton Rouge

If you're interested in a free day of PowerShell training, there are numerous sessions on different topics in the dedicated PowerShell track at SQL Saturday #628 in Baton Rouge, Louisiana this Saturday, July 29th. I'll be presenting a session on how to "Automate Operational Readiness and Validation Testing of SQL Server with PowerShell and Pester". Here’s a little information about what you can expect from my session: Automate Operational Readiness and Validation Testing of SQL Server Read more [...]

Remove all user defined variables without restarting the PowerShell Console or ISE

Recently, fellow Microsoft MVP Mickey Gousset asked me how to remove existing user defined variables from the PowerShell ISE (Integrated Scripting Environment) before running a script a second time without having to restart the ISE. While you could keep track of the variables you've used within your script to remove them once the script completes with the Remove-Variable cmdlet or by deleting them from the variable PSDrive, that can be a less than desirable solution for long and complicated scripts Read more [...]

Copy databases from 5 different SQL Servers in 100 seconds with the DBATools PowerShell Module

As referenced in my blog article from yesterday, I'll be presenting a PowerShell 101 session at SQL Saturday Atlanta tomorrow morning (July 15, 2017). While I plan to cover the basics of PowerShell, I also plan to show you what you can do with PowerShell without having to write very much code at all. I'll be killing it in my session with live demos including this one that I've made a video of as a sneak preview. If the video embedded in this webpage doesn't display Read more [...]

Presenting PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell this weekend at SQL Saturday Atlanta

If you're interested in some free PowerShell training where you'll learn the basics of PowerShell from a best practices standpoint, I'll be presenting a session on "PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell" at SQL Saturday #652 in Atlanta, Georgia this Saturday, July 15th. My presentation begins at 8am eastern time and is a beginner level session. There's also a Powering Azure from PowerShell session that Microsoft MVP Robert Cain is presenting at 2:15pm. Here’s Read more [...]

Encrypt a Password with PowerShell for use by a Different User and/or on a Different Computer

Storing a password in an encrypted file for use by the same user on the same computer using PowerShell is fairly easy, but storing a password in an encrypted file for use on another computer or by another user is a bit more challenging. It requires the use of a key file and of course if someone else can read the key file, then they also can decrypt the password. In my scenario, I work in a VDI (Virtual Desktop Infrastructure) environment that doesn't use persistent desktops and I need to have Read more [...]

Renewed as a Microsoft Cloud & Datacenter Management MVP

I'm honored and humbled to have been awarded the Microsoft MVP award for a fourth consecutive year. I received email notification yesterday confirming that I've been renewed for another year. The first two Microsoft MVP awards that I received were for PowerShell and due to changes to Microsoft's MVP award program, the latest two have been for Cloud and Datacenter Management, although my focus is still PowerShell. In addition to being a multiyear recipient of the Microsoft MVP award, I'm also Read more [...]

Automatically Customizing the PowerShell ISE on Startup

This past weekend while at SQL Saturday Chattanooga, I was asked if it was possible to have the PowerShell ISE (Integrated Scripting Environment) automatically open with a right/left split pane: Instead of the top/bottom default split pane: One thing to note is that by default the PowerShell ISE will reopen in whatever configuration you close it in, which could be either of the ones previously shown or the full screen editor. If you want the ISE to open with a certain configuration Read more [...]

Presenting PowerShell Non-Monolithic Script Module Design this weekend at SQL Saturday Chattanooga

If you’re interested in some free PowerShell training, I’ll be presenting a session on "PowerShell Non-Monolithic Script Module Design" at SQL Saturday #624 in Chattanooga, Tennessee this Saturday, June 24th. My presentation begins at 1:15pm eastern time and is an intermediate level session. There's also a PowerShell precon on Friday being presented by Microsoft MVP Aaron Nelson (the precon is not free) and a PowerShell DSC (Desired State Configuration) session on Saturday being presented Read more [...]