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.
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.
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:
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.
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:
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.