How to run SQL Commands from PowerShell

Written by Paul Hill on July 23, 2021

Paul Hill is the founder of and IT instructor to over 500,000 students online!

If you want to run SQL commands from your PowerShell terminal you can do so by simply installing the SQLServer module with the command below:

Install-Module sqlserver
Install SQLServer PowerShell Module

You will be prompted to install from an untrusted source. Type “A” to accept and install the module.

Once it is complete you can see all the new commands you have available to you by running the following command:

Get-Command -Module SQLServer
Image 1
All the SQLServer PS Module Commands

And that’s it! Now you can run commands like Invoke-SqlCMD!

Get the "Intro to IT" ebook FREE!

The ebook covers IT basics and will help you get started with building your IT career.  Enter your email below and we'll send you this powerful ebook along with other useful IT tips!

Table of Contents
    Add a header to begin generating the table of contents

    Sign up free and start learning today!

    Practice on REAL servers, learn from our video lessons, interact with the Server Academy community!