Tag: PowerShell

My Solution to Iron Scripter 2019 Preparatory Challenge 1

Anyone who has competed in the scripting games before knows that I'm always looking for a challenge when it comes to writing PowerShell code. While the scripting games haven't been held in the last several years, they've somewhat been replaced by the Iron Scripter competition at the PowerShell + DevOps Global Summit and 2019 is shaping up to be no different. Think you've got skills? Bring them on! and Get-Involved. Whether you've previously competed or not, you should definitely head over to IronScripter.us Read more [...]

Unexpected Results when Comparing Different Datatypes in PowerShell

Earlier this week, I saw a tweet from a fellow PowerShell community member who mentioned PowerShell was returning inaccurate results. The command shown in the tweet was similar to the one in the following example. Why would results be returned where "IsFramework" is true when the command is filtering them down to only the ones that are false? I knew exactly what the problem was because I've been bit by it more times than I care to remember. Piping the Get-AppxPackage Read more [...]

What’s a PowerShell One-Liner & NOT a PowerShell One-Liner?

Lately, I've seen a few examples of commands that aren't PowerShell one-liners being passed off as such by people in the PowerShell community who "should" know better. If I were interviewing someone who claimed to be a PowerShell expert with more than five years of experience, I would definitely ask these types of questions. Example 1 - The following command is a PowerShell one-liner? (True or False) Example 2 - The following command is a PowerShell one-liner? Read more [...]

Return a List of the Private Functions in a PowerShell Module

In my quest to build a PowerShell module to convert a non-monolithic PowerShell module from development to a monolithic one for production, I wanted some way to validate that all of the functions were indeed migrated. While I'm pointing my tools to the public and private sub-folders within my development module and that should get them all, how can you be sure especially when a module may not have any private functions? Determining the publicly accessible functions for a module is easy enough Read more [...]

Resolving Microsoft SQL Server Error 4064 with PowerShell

Recently, a fellow IT Pro contacted me and stated they were unable to login to one of their SQL Servers using Windows Authentication. The following error was generated when attempting to login to SQL Server Management Studio (SSMS). Their exact words were "I think we have a permissions problem". Clicking on the "Show technical details" icon at the bottom of that error message showed the following information. You can work around this problem by clicking on the "Options >>" button: Then Read more [...]

Finish the year off helping others in the PowerShell Community

If you follow my blog, then I'm sure you're aware that earlier this year I embarked on a project to help others get started with PowerShell. I leveraged the contacts I'd made over the years in the PowerShell community and created a book with many of them, named "The PowerShell Conference Book". We all donated our time as 100% of the royalties go towards funding scholarships for the OnRamp track at the PowerShell + DevOps Global Summit. So far, we've fully funded three scholarships ($4,000 Read more [...]

Book Sale! Save on my PowerShell 101 Book & The PowerShell Conference Book

There's never been a better time to purchase my PowerShell 101: The No-Nonsense Beginner’s Guide to PowerShell eBook. It's currently on sale for $4.99 using this link which automatically includes a coupon code that's good from now until the end of the year or for the first 50 redemptions, whichever comes first. Not sure whether or not this book is for you? Download the free sample which includes the first two chapters.
About the Book

Before PowerShell, I spent the first third of my career Read more [...]

Use PowerShell to Install a DHCP Server on a Windows Server 2019 (Server Core) Active Directory Domain Controller

You need to have an Active Directory domain in place. I'm picking up where I left off in my previous blog article "Use PowerShell to Create a New Active Directory Forest on Windows 2019 Server Core Installation (no-GUI)".
The procedure shown in this blog article is for demonstration purposes only.
Install the DHCP server feature.

Add the DHCP scope to the server.

Options can either be set at the scope level.

Or Read more [...]

Use PowerShell to Create a New Active Directory Forest on Windows 2019 Server Core Installation (no-GUI)

You have a fresh installation of Windows Server 2019 that was installed using the default installation type of server core installation (no-GUI). This server will be the first domain controller in a brand new Active Directory forest. You've completed the following configuration prior to attempting to turn this server into a domain controller:

Install all the available Windows Updates
Set the time zone
Set the computer name
Set a static IP address

Log into the server and launch PowerShell Read more [...]

What’s the Recommended Editor for PowerShell Scripts?

You've probably heard, as I have, that Visual Studio Code (VSCode) is the latest whiz-bang editor that you should be using for PowerShell (and I am for development of PowerShell code on my primary workstation). One word of caution though is to make sure to put things into perspective and not be so quick to shun people away from using the PowerShell Integrated Scripting Environment (ISE), depending on how they're using it.

I recently received a comment about my choice of editors for a particular Read more [...]

Managing the Hyper-V Default Switch in Windows 10 version 1709 and higher with PowerShell

Windows 10 version 1709 introduced a default Hyper-V virtual switch which is installed when the Hyper-V role is added. As you can see in the following example, by default on Windows 10, the default virtual switch does not exist because the Hyper-V role hasn't been added.

Now that the Hyper-V role has been added, you can see that a new network adapter named "vEthernet (Default Switch)" exists.

While you wouldn't think this Read more [...]

PowerShell Script Module Design: Building Tools to Automate the Process

As I previously mentioned a little over a month ago in my blog article "PowerShell Script Module Design Philosophy", I'm transitioning my module build process to a non-monolithic design in development and a monolithic design for production to take advantage of the best of both worlds. Be sure to read the previously referenced blog article for more details on the subject.

My goal is to write a reusable tool to retrieve the necessary information from a non-monolithic script module that's necessary Read more [...]

Learn about the PowerShell Abstract Syntax Tree (AST) – Part 3

This blog article is the third in a series of learning about the PowerShell Abstract Syntax Tree (AST). Be sure to read the other two if you haven't already.

Learning about the PowerShell Abstract Syntax Tree (AST)
Learn about the PowerShell Abstract Syntax Tree (AST) – Part 2
Learn about the PowerShell Abstract Syntax Tree (AST) – Part 3

In this blog article, I'll be specifically focusing on finding the AST recursively.

I'll start off by storing the path to one of my functions Read more [...]

Learn about the PowerShell Abstract Syntax Tree (AST) – Part 2

In my previous blog article a few weeks ago on "Learning about the PowerShell Abstract Syntax Tree (AST)", I mentioned there was an easier way to retrieve the AST so that you didn't have to cast everything to a script block. There are two .NET static methods, ParseFile and ParseInput, that are part of the Parser class in the System.Management.Automation.Language namespace which can be used to retrieve the AST.

First, I’ll store the content of one of my functions in a variable.

The Read more [...]

Use PowerShell to Monitor IIS Websites and Application Pools

I recently received a request to write a script for monitoring IIS websites and their application pools on a specific Windows 2012 R2 server and start them if they were stopped. This is something I created fairly quickly and thought I would share.

I always try to centralize any scripts I write and have them run on a job server instead of the actual server they're querying. That way I don't have multiple versions of the same script floating around on different servers. I can easily use this same Read more [...]

Use PowerShell to Install the Remote Server Administration Tools (RSAT) on Windows 10 version 1809

My computer recently updated to Windows 10 version 1809 and as with all previous major updates of Windows 10, this wipes out the Remote Server Administration Tools (RSAT).

However, unlike previous versions, Microsoft has now made RSAT available via Features on Demand and while you're supposed to be able to install them from the GUI, they never showed up as being an option for me.

That's not really a problem though since they can now be installed via PowerShell. Who needs a GUI anyway?

The Read more [...]