Click here to Skip to main content
15,885,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Below is the code I am nusing for disabling shared memory in sql. It is not working. can anyone have a look into it.


Param([string]$serverName = $(Read-Host "SQL Instance(like server\instance)")

)

# Load the assemblies

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

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

function EnableDisableServerProtocol

{
# Spilt Machine , instance names

$array = $serverName.Split("\")

#Write-Host " " $serverName
if([String]::IsNullOrEmpty($serverName))

{

write-error "Server instance name is not valid"

return

}

$machineName = $array[0]



if($array.Length -eq 1)

{

$instanceName = "MSSQLSERVER"

}

else

{

$instanceName = $array[1]

}

#Write-Host " " $serverName
$Services=get-wmiobject -class win32_service -computername $machineName| where {$_.name -like '*SQL*'}| select-object *

$sname = $instanceName

#write-host $sname

#Get a managed computer instance

$mc = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer')

# Disable Shared Memory Protocal

$urnSM = New-Object -TypeName 'Microsoft.SqlServer.Management.Sdk.Sfc.Urn' -argumentlist "ManagedComputer[@Name='$machineName']/ServerInstance[@Name='$sname']/ServerProtocol[@Name='sm']"

#Get the protocol object

$Sm = $mc.GetSmoObject($urnSM)

#enable the protocol on the object

$Sm.IsEnabled = $false

#propagate back to actual service

$Sm.Alter()

}


EnableDisableServerProtocol
$service = get-service "MSSQLSERVER"
restart-service $service.name -force #Restart SQL Services
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900