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?
答案 0 :(得分: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.
答案 1 :(得分:1)
您可以将其安装为独立的PowerShell模块。
请以管理员身份打开Powershell并执行以下操作:
Set-ExecutionPolicy unrestricted
Install-Module sqlserver
Import-Module sqlserver
这应该允许您通过Powershell运行Sql命令,而无需安装SQL Server Management Studio。