1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #################################
# @author = Mikedavem #
# @Description = #
# Activation du protocole TCPIP #
# et désactiviation des canaux #
# nommés. #
#################################
$computername = "computer";
$login = "login";
$pwd = convertto-securestring "motdepasse" -asplaintext -force;
try
{
# Définition du crédential
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $login,$pwd -ErrorAction "silentlycontinue";
# Protocol Canaux nommés à désactiver
$protocol = Get-WmiObject -computername $computername -credential $credential -namespace "root\Microsoft\SqlServer\ComputerManagement" `
-class ClientNetworkProtocol `
-filter "ProtocolName='np'" `
-ErrorAction "silentlycontinue";
$protocol.SetDisable();
# Protocol TCP à activer
$protocol = Get-WmiObject -computername $computername -credential $credential -namespace "root\Microsoft\SqlServer\ComputerManagement" `
-class ClientNetworkProtocol `
-filter "ProtocolName='tcp'";
$protocol.SetEnable();
# Redémarrage service SQL
$sqlservice = Get-WmiObject -computername $computername -credential $credential -namespace root\Microsoft\SqlServer\ComputerManagement `
-class SqlService `
-filter "ServiceName='MSSQLSERVER'" `
-ErrorAction "silentlycontinue";
$sqlservice.StopService();
$sqlservice.StartService();
}
catch
{
"Une erreur est survenue lors de la mise à jour des protocoles :";
"Détail de l'erreur :"
$err = $Error[0];
$err | Format-List *;
} |
Partager