5

I have been using the MSDN article Enable or Disable a Server Network Protocol (SQL Server PowerShell) and am running into issues on the line:

$uri = "ManagedComputer[@Name='<computer_name>']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Np']"

The error message I get is:

Exception calling "GetSmoObject" with "1" argument(s): "Attempt to retrieve data for object failed for ManagedComputer '<computer_name>'."
At line:1 char:24
+ $Np = $wmi.GetSmoObject <<<< ($uri)
    + CategoryInfo           : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId  : DotNetMethodException

I am replacing <computer_name> with the name of my computer. I have also tried omitting <computer_name> from my command (I am trying to configure the machine from which I am running the script), and the I get the same error, including it showing the correct <computer_name> in the error. I have also tried omitting everything from the first / on, with no luck.

I have tried using cmd, powershell, and sqlps. I am logged in as Administrator, and all of my windows say Administrator at the top, so I take that to mean that I am running the commands as administrator.

I am running on Windows Server 2012, with MS Sql Server 2012 installed.

My long term goal is to create a utility to setup SQL Server on a new machine without the need for user interaction.

How can I resolve my issue with the line of code from the MSDN article?

3
  • 1
    As written the code will only work on a default instance. Are you by chance using a named instance? Oct 16, 2013 at 11:17
  • @ChadMiller I believe I am using the default instance. I don't specify an instance name when I log-in through SSMS, and when I do SELECT @@SERVICE the result is MSSQLSERVER.
    – Brian J
    Oct 16, 2013 at 12:46
  • I included this line at the beginning of the powershell script: Import-Module "sqlps" -DisableNamechecking and went back to explicitly putting in the <computer_name>, and now it works. I think I was getting errors because of not doing the import module, but by the time I imported it, I started leaving the computer name blank, and started getting XPath errors.
    – Brian J
    Oct 16, 2013 at 13:27

3 Answers 3

1

If you failed like me for SQLExpress (version 12 = 2014):

look at this registry location:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQLServer\SuperSocketNetLib\Tcp

the manager shows the value, but I cannot change the values in Win10 - UI issue. C:\Windows\System32\SQLServerManager12.msc

0

I included this line at the beginning of the powershell script:

Import-Module "sqlps" -DisableNamechecking

and went back to explicitly putting in the <computer_name>, and now it works.

I think I was getting errors because of not doing the import module, but by the time I imported it, I started leaving the computer name blank, and started getting XPath errors.

1
  • My issue was similar... I had the computer name in a variable and therefore thought I didn't need quotes around it. Turns out, it needs quotes.
    – Flat Cat
    Jul 11, 2017 at 22:07
0

Enable TCP and Named Pipes on a Named SQL Server instance Tested against Server 2022 Express

[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")

$smo = 'Microsoft.SqlServer.Management.Smo.'  
$wmi = new-object ($smo + 'Wmi.ManagedComputer').
$SQLInstance = $wmi.ServerInstances.Name

#note the dynamic retrieval of the instance name; obviously, this would not work if you had more than one named instance installed on the machine
$uri = "$($wmi.urn.value)/ServerInstance[@Name=`'$SQLInstance`']/ServerProtocol[@Name='Tcp']"
$Tcp = $wmi.GetSmoObject($uri)
$Tcp.IsEnabled = $true
$Tcp.Alter()
$uri = "$($wmi.urn.value)/ ServerInstance[@Name=`'$SQLInstance`']/ServerProtocol[@Name='Np']"
$Np = $wmi.GetSmoObject($uri)
$Np.IsEnabled = $true
$Np.Alter()

Restart-Service "MSSQL`$$($SQLInstance)"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.