To change the IP address in sql servers’ configuration manager, you can use the following code. Of note, when I changed the IP address in configuration manager under IP1 manually and tested connections, it really didn’t make a lick of difference. I could connect whether or not the IP1 value reflected the correct IP address or not. But, having a different IP listed in the configuration manager as opposed to what it really is just feels dishonest.
Import-Module SqlPS -DisableNameChecking
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | out-null
cls
try{
$srvName = "servername"
$Instance = "mssqlserver"
$urn = "ManagedComputer[@Name='$srvName']/ServerInstance[@Name='$Instance']/ServerProtocol[@Name='Tcp']"
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer $srvName
$tcp = $wmi.GetSmoObject($urn);
$tcp.IPAddresses["IP1"].IPAddressProperties["IpAddress"].Value = '10.10.1.1';
$tcp.Alter();
}
catch{
$_ | fl -Force
}
Leave a comment