Skip to content

Instantly share code, notes, and snippets.

@marrobi
Created March 9, 2017 11:30
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 marrobi/806f464c47b81bddc297442d5d1d8e72 to your computer and use it in GitHub Desktop.
Save marrobi/806f464c47b81bddc297442d5d1d8e72 to your computer and use it in GitHub Desktop.
Replace DB connections
Param
(
[string]$ServerHostName,
[string]$User,
[string]$Password,
[string]$DBName,
[string]$GeoServerDataDir
)
# find all datasource.xml files in X:\workspaces
foreach($datastore in (Get-ChildItem "$GeoServerDataDir\workspaces\" -Include "datastore.xml" -Recurse)){
# replace user, host and password
$xml = [xml](Get-Content $datastore.FullName)
$xml.dataStore.connectionParameters.entry | where {$_.key -eq "user"} | % { $_."#text" = $User }
$xml.dataStore.connectionParameters.entry | where {$_.key -eq "host"} | % { $_."#text" = $ServerHostName }
$xml.dataStore.connectionParameters.entry | where {$_.key -eq "passwd"} | % { $_."#text" = $Password }
# if not OS Master maps switch DB
if(($xml.dataStore.connectionParameters.entry | where {$_.key -eq "database"})."#text" -ne "osmm"){
$xml.dataStore.connectionParameters.entry | where {$_.key -eq "database"} | % { $_."#text" = $DBName }
}
# save the file
$xml.Save($datastore.FullName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment