Skip to content

Instantly share code, notes, and snippets.

@BrendanThompson
Created October 8, 2014 07:14
Show Gist options
  • Save BrendanThompson/0f7798291fd98df9edf2 to your computer and use it in GitHub Desktop.
Save BrendanThompson/0f7798291fd98df9edf2 to your computer and use it in GitHub Desktop.
Function to update Key Value pairs in Configuration Files
Param(
[string]$configurationFilePath,
[string]$configKey,
[string]$configValue
)
((Get-Content -Path $configurationFilePath) | Foreach-Object {
$line = $_
if ($line -like "*=*") {
$lineArray = $line -split "=", 2
if ($lineArray[0].Trim() -eq $configKey) {
$lineArray[1] = $configValue
$line = $lineArray -join "="
}
}
$line
}) | Set-Content ($configurationFilePath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment