Blog Post

Installing PowerShell for SQL Server – #SQLNewBlogger

,

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

PowerShell is the hot new scripting language for working with processes outside of an application. It’s cross platform, and it has a lot of capabilities for working with SQL Server. The way that this gets installed has changed, so this is a quick post to ensure others know how to do this.

Running a Command

I know there is an Invoke-SqlCmd cmdlet in PowerShell. On a new laptop, I tried to run it and had issues.

2019-12-17 15_57_22-cmd - powershell

SQLPS is the old module, and SqlServer is the new one. The error message says to try importing the module, so let’s do that.

2019-12-17 15_59_40-cmd - powershell

That doesn’t work either. Hmmm. I think I need to install this. To do that, I need an elevated command prompt. I’m using ConEmu, and I can restart this session as an admin. Or you can use the start menu to find cmd and start this as an admin:

2019-12-17 16_02_41-Installing PowerShell for SQL Server - #SQLNewBlogger - Open Live Writer

Once you have an elevated prompt, start PowerShell and then run this:

Install-Module SqlServer

This will install the module if you answer the prompts correctly. I had to use the -AllowClobber parameter as I had some conflicting things installed from dbatools. I’ll likely update those after this with their own AllowClobber.

2019-12-17 16_05_24-cmd - powershell (Admin)

Once this is done, you should be able to use the cmdlets. First you import the module with this:

Import-Module SqlServer

Then you can run code:

2019-12-17 16_08_05-cmd - powershell (Admin)

SQLNewBlogger

After getting a new laptop, I needed to set a few things up. PowerShell was one of those. As I started to do this, I grabbed screenshots to document the process for my blog. I then built this post in about 10 minutes.

You could do this as well, to round out the knowledge you gain as you do something similar, and show you’re familiar with these concepts.

Original post (opens in new tab)
View comments in original post (opens in new tab)

Rate

5 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (1)

You rated this post out of 5. Change rating