Created
March 9, 2017 11:30
-
-
Save marrobi/806f464c47b81bddc297442d5d1d8e72 to your computer and use it in GitHub Desktop.
Replace DB connections
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
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