Reputation: 4590
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?
Upvotes: 1
Views: 1865
Reputation: 1731
You can install this as an independent PowerShell module.
Kindly open Powershell as an administrator and do the following:
Set-ExecutionPolicy unrestricted
Install-Module sqlserver
Import-Module sqlserver
This should allow you to run Sql Commands through Powershell without installing SQL Server Management Studio.
Upvotes: 2
Reputation: 47792
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.
Upvotes: 1