Skip to content

Instantly share code, notes, and snippets.

@nbarnwell
Last active August 29, 2015 14:17
Show Gist options
  • Save nbarnwell/6b7772a230a449c9f992 to your computer and use it in GitHub Desktop.
Save nbarnwell/6b7772a230a449c9f992 to your computer and use it in GitHub Desktop.
Update-ConnectionString
function Update-ConnectionString {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string[]] $ConnectionString,
[Parameter(Mandatory = $true)]
[string] $PropertyName,
[Parameter(Mandatory = $true)]
[string] $Value)
begin {
$PropertyName = Remove-WhiteSpace $PropertyName
$Value = Remove-WhiteSpace $Value
}
process {
($ConnectionString |
%{ $_ -split ';' } |
%{
($k, $v) = $_ -split '=' | Remove-WhiteSpace
if ($k -eq $PropertyName) {
"$k=$Value"
} else {
$_
}
}) -join ';'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment