How to configure native SQL client using powershell?

I was tasked with writing a script that would include TCP and named pipes for an instance of SQL Server 2008 Express R2. I learned how to enable these protocols for the instance of SQL Server itself, but I did not find a way to manage my own native SQL client from powershell.

My script is part of the installer, and the code I install expects these protocols to be enabled.

thank

+3
source share
2 answers

I finally found a solution. Protocols can be enabled by setting the registry key:

c HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\SNI10.0, set the key ProtocolOrderto enable the protocols that should be included:

sm = Shared memory
np = Named pipes
tcp = TCP (he)
via = Via

Protocols not specified in this key will be disabled.

+1
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")
$wmi = new-object ("Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer") "$env:computername"
$wmi.ServerInstances["SQLEXPRESS"].ServerProtocols["Tcp"].IsEnabled = $true
$wmi.ServerInstances["SQLEXPRESS"].ServerProtocols["Np"].IsEnabled = $true
$wmi.ClientProtocols["tcp"].IsEnabled = $true
$wmi.ClientProtocols["np"].IsEnabled = $true
+5

Source: https://habr.com/ru/post/1792897/


All Articles