Created
August 31, 2012 15:43
-
-
Save jbubriski/3554843 to your computer and use it in GitHub Desktop.
Update NCache config IP's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$clientConfigurationFile = 'C:\Program Files\NCache\config\client.ncconf' | |
$serverConfigurationFile = 'C:\Program Files\NCache\bin\service\Alachisoft.NCache.Service.exe.config' | |
$ips = ipconfig | Where-Object {$_ -match "IPv4 Address"} | foreach-object{$_.Split(":")[1].Trim()} | |
if ($ips -is [system.array]) | |
{ | |
$newIp = $ips[0].ToString() | |
} | |
else | |
{ | |
$newIp = $ips.ToString() | |
} | |
#Update Client Configuration | |
[xml] $xml = gc $clientConfigurationFile | |
$xml.configuration.ChildNodes | |
foreach ($node in $xml.configuration.ChildNodes) | |
{ | |
foreach ($cache in $node.ChildNodes) | |
{ | |
$cache.name = $newIp | |
} | |
} | |
$xml.save($clientConfigurationFile) | |
#Update Server Configuration | |
[xml] $xml = gc $serverConfigurationFile | |
$appSettings = $xml.configuration.appSettings.ChildNodes | |
$bindToClusterIP = $appSettings | Where-Object {$_.key -eq "NCacheServer.BindToClusterIP"} | |
$bindToClusterIP.value = $newIp | |
$bindToClientServerIP = $appSettings | Where-Object {$_.key -eq "NCacheServer.BindToClientServerIP"} | |
$bindToClientServerIP.value = $newIp | |
$xml.save($serverConfigurationFile) | |
# Restart NCache | |
Restart-Service NCache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment