2011-10-10 67 views
1

有人嘗試使用PowerShell配置SQL Server構面...我試着用下面的代碼..我能夠找出構面的屬性,但沒有得到如何設置這些值的想法屬性。Powershell配置SQL Server構面


[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Dmf') | Out-Null 
[System.Reflection.Assembly]::LoadWithPartialNam('Microsoft.SQLServer.Management.Sdk.Sfc') | Out-Null 
$conn = New-Object Microsoft.SQlServer.Management.Sdk.Sfc.SqlStoreConnection("server='Ramu-pc';Trusted_Connection=true") 
$PolicyStore = New-Object Microsoft.SqlServer.Management.DMF.PolicyStore($conn) 
$facets = [Microsoft.SqlServer.Management.Dmf.PolicyStore]::Facets | Where {$_.Name -eq 'ISurfaceAreaFacet'} 
$facets | Format-Table –Auto 

當我執行下面的命令,我看到不同的方法,但我沒有得到如何使用這些方法的幫助。 $ Facets |克

我需要在上面刻面配置以下值:

  • AdHocRemoteQueriesEnabled =真
  • 的xp_cmdshell =真

回答

0

雖然它不完全使用你展示什麼,但這裏是我用什麼。


[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null 
$server = New-Object 'Microsoft.SqlServer.Management.SMO.Server' ('Ramu-pc') 
$server.Configuration.AdHocDistributedQueriesEnabled.ConfigValue = 1 
$server.Configuration.XPCmdShellEnabled.ConfigValue = 1 
$server.Configuration.Alter() 
0

您可以用正常的批次和sp_configure的

自動化我希望這可以幫助別人找到答案,同時自動設置方面,這將有救了我一些時間。

替換爲AdHocRemoteQueriesEnabled爲您的答案,而不是我的工作示例下面的「遠程訪問」。

與您類似我正在尋找一種自動化方式,我的情況是RemoteAccessEnabled,而不是在任何目標上安裝管理器 我想設置爲主控的機器。上述特殊關鍵字甚至沒有在搜索中註冊。

sp_configure的Transact-SQL語句:

exec sp_configure "remote access", 1 

也:

remote query timeout 
remote proc trans 

HTH有人