Got this code from a friend, if someone has a cleaner way of replacing values in a config file before deployment feel free to post it below. Using function updatefile and some code to pull config out of a CSV. I know you could do an ini instead of a csv. It's the updating the config after you have the value I wish was cleaner. Hope this helps someone with multiple locations.
Function UpdateFile
{
$site = $computername.substring(0,3)
$CSVfile = 'FacilityServers.csv'
$CSV=Import-Csv $CSVfile
[String]$Facility = $CSV | Where-Object {$_.'site' -eq $site} | select 'Facility'
$Facility = $Facility.Replace("@{Facility=","")
$Facility = $Facility.Replace("}","")
$OLDSTRING = "XXXXXXXXXXXX"
$NEWSTRING = $GUIServer
Site,GUIServer,Facility
ABC,ABCGUI01,ABC,
config file
[Global]
Replacenew=7za.exe,"XXXXXXXXXXXX\main\update\
Function UpdateFile
{
$file = Get-ChildItem $FILENAME
foreach ($str in $file)
{
$content = Get-Content -path $str
$content | foreach {$_ -replace $OLDSTRING,$NEWSTRING} | Set-Content $str
}
}$site = $computername.substring(0,3)
$CSVfile = 'FacilityServers.csv'
$CSV=Import-Csv $CSVfile
[String]$Facility = $CSV | Where-Object {$_.'site' -eq $site} | select 'Facility'
$Facility = $Facility.Replace("@{Facility=","")
$Facility = $Facility.Replace("}","")
-----------------------------------------
$FILENAME = "main.conf"$OLDSTRING = "XXXXXXXXXXXX"
$NEWSTRING = $GUIServer
-----------------------------------
CSV file contentsSite,GUIServer,Facility
ABC,ABCGUI01,ABC,
config file
[Global]
Replacenew=7za.exe,"XXXXXXXXXXXX\main\update\