加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

powershell connects to sqlserver

发布时间:2020-12-12 14:13:25 所属栏目:MsSql教程 来源:网络整理
导读:How to issue sql query to sql server database by using powershell ? Here is the Link :?http://sev17.com/2010/07/making-a-sqlps-module/ Steps: 1) Make a module? ? ? 1.1) Copy file/folder under 100/Binn to powershell/vx.0/modules/sqlps en Mi

How to issue sql query to sql server database by using powershell ?


Here is the Link :?http://sev17.com/2010/07/making-a-sqlps-module/


Steps:

1) Make a module?

? ? 1.1) Copy file/folder under 100/Binn to powershell/vx.0/modules/sqlps

  • en
  • Microsoft.SqlServer.Management.PSProvider.dll
  • Microsoft.SqlServer.Management.PSSnapins.dll
  • SQLProvider.Format.ps1xml
  • SQLProvider.Types.ps1xml

? ? 1.2) create a file named "sqlps.psd1"

@{

ModuleVersion="0.0.0.1"
Description"A Wrapper for Microsoft's SQL Server PowerShell Extensions Snapins"
Author"Chad Miller"
Copyright"? 2010,Chad Miller,released under the Ms-PL"
CompanyName"http://sev17.com"
CLRVersion"2.0"
FormatsToProcess"SQLProvider.Format.ps1xml"
NestedModules"Microsoft.SqlServer.Management.PSSnapins.dll","Microsoft.SqlServer.Management.PSProvider.dll"
RequiredAssemblies"Microsoft.SqlServer.Smo""Microsoft.SqlServer.Dmf""Microsoft.SqlServer.SqlWmiManagement""Microsoft.SqlServer.ConnectionInfo""Microsoft.SqlServer.SmoExtended""Microsoft.SqlServer.Management.RegisteredServers""Microsoft.SqlServer.Management.Sdk.Sfc""Microsoft.SqlServer.SqlEnum""Microsoft.SqlServer.RegSvrEnum""Microsoft.SqlServer.WmiEnum""Microsoft.SqlServer.ServiceBrokerEnum""Microsoft.SqlServer.ConnectionInfoExtended""Microsoft.SqlServer.Management.Collector""Microsoft.SqlServer.Management.CollectorEnum"
TypesToProcess"SQLProvider.Types.ps1xml"
ScriptsToProcess"Sqlps.ps1"
}

? ? 1.3) craete a file named "sqlps.ps1"

Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
-name SqlServerConnectionTimeout 30
-name SqlServerIncludeSystemObjects $false
-name SqlServerMaximumTabCompletion 1000

2) import-module SQLPS?


Now you can issues query to sql server by using invoke-sqlcmd -query xxxx -database xxxx -serverinstance xxxx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读