1

I`m trying to modify and use powershell script from learn.microsoft.com in order to enable SQL Shared Memory protocol on a remote server. But my issue is instead of connecting to provided ManagedComputer and ServerInstance parameters, the script tries to execute it locally and I get below error:

# Load the assemblies
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement")

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

# List the object properties, including the instance names.
$Wmi

$uri = "ManagedComputer[@Name='<computer_name>']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Sm']"
$Sm= $wmi.GetSmoObject($uri)
$Sm.IsEnabled = $true
$Sm.Alter()
$Sm

Exception calling "GetSmoObject" with "1" argument(s): "Attempt to retrieve data for object failed for ManagedComputer 'my computer name."

Ive searched a lot for similar problems but none of the suggested solutions didnt help, as I want to enable the protocol on remote server and if it works, to automate the script by running on multiple instances. But for now, my aim is to make it work at least on one remote server. Will appreciate your thoughts on this.

2
  • dup on SO
    – SMor
    Aug 10, 2022 at 11:11
  • It might be simpler to use Powershell Remoting or SQL Agent to run the powershell on the target server. Aug 10, 2022 at 19:10

0

Your Answer

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

Browse other questions tagged or ask your own question.