Sql server 如何运行sp#u configure';即席分布式查询';来自PowerShell?

Sql server 如何运行sp#u configure';即席分布式查询';来自PowerShell?,sql-server,powershell,octopus-deploy,Sql Server,Powershell,Octopus Deploy,要启用“临时分布式查询”,我可以在SQL中运行以下语句。有人知道如何从PowerShell启用吗 sp_configure 'show advanced options', 1 reconfigure GO sp_configure 'Ad Hoc Distributed Queries', 1 reconfigure 尝试此操作,用适合您环境的正确参数替换和: $sql = '@ sp_configure 'show advanced options', 1 reconfigure GO s

要启用“临时分布式查询”,我可以在SQL中运行以下语句。有人知道如何从PowerShell启用吗

sp_configure 'show advanced options', 1
reconfigure
GO
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure

尝试此操作,用适合您环境的正确参数替换

$sql = '@
sp_configure 'show advanced options', 1
reconfigure
GO
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
'@

Invoke-SqlCmd -Query $sql -ServerInstance <SQL server> -Database <database name>
$sql=>@
sp_配置“显示高级选项”,1
重新配置
去
sp_配置“临时分布式查询”,1
重新配置
'@
调用SqlCmd-Query$sql-ServerInstance-Database
此处突出显示的语法无助于说明
@'
表示“此处字符串”,它允许所有字符直到
@
为止,因为换行符上的第一个字符表示字符串的结尾。

请尝试此脚本

$query = "
sp_configure 'show advanced options', 1
reconfigure
GO
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
"

Invoke-SqlCmd -Query $query -ServerInstance <Your Server Name>
$query=”
sp_配置“显示高级选项”,1
重新配置
去
sp_配置“临时分布式查询”,1
重新配置
"
调用SqlCmd-Query$Query-ServerInstance

尝试
调用SqlCmd
,将
-ServerInstance
作为服务器传递,将
-Database
作为要运行的数据库传递。