1

I am developing an automation system that will grant access to SQL Server databases through Powershell by running a query. I am able to do this just fine, but my question is, do I need to install SQL Server Management Studio in order to import the modules

For example:

import-module sqlserver

When I attempted this before I installed studio I was unable to install because Powershell could not find the module.

Once I had the module imported, I was able to run the follow command:

Invoke-sqlcmd -query "grant select, insert, update on test to sqlsupport;" -serverinstance "test\test"

Is there a way to have the modules available without studio?

2 Answers 2

2

You can install this as an independent PowerShell module.

Kindly open Powershell as an administrator and do the following:

  1. Run Set-ExecutionPolicy unrestricted
  2. Run Install-Module sqlserver
  3. Run Import-Module sqlserver

This should allow you to run Sql Commands through Powershell without installing SQL Server Management Studio.

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, in the same installer for SSMS, by selecting the components to install, you can choose to install only the PowerShell cmdlets and not the rest of SSMS.

You should also make sure you're using the latest module (they changed the name from SQLPS to SqlServer); as of this writing it's the July 2016 update.

2 Comments

I don't see where during the install it will give me the option to select which components are install. I have two options, Install or Close.
@BrandonWilson it may not be the SSMS installer, it might be a "tools" installer or the SQL with advanced services installer, where you can choose not to install SSMS but just install the powershell cmdlets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.