Quantcast
Channel: PowerShell App Deployment Toolkit
Viewing all articles
Browse latest Browse all 2341

New Post: Update a config file from CSV

$
0
0
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
{
$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 contents
Site,GUIServer,Facility
ABC,ABCGUI01,ABC,

config file
[Global]
Replacenew=7za.exe,"XXXXXXXXXXXX\main\update\

Viewing all articles
Browse latest Browse all 2341

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>