Skip to content

Instantly share code, notes, and snippets.

@jbubriski
Created August 31, 2012 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbubriski/3554843 to your computer and use it in GitHub Desktop.
Save jbubriski/3554843 to your computer and use it in GitHub Desktop.
Update NCache config IP's
$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