Last active
November 22, 2017 09:13
-
-
Save rdbartram/9478ed7bfe7436f3c0e03d5403da4ecc to your computer and use it in GitHub Desktop.
Accepts SQL Connection strings and converts them to and from powershell objects for easy manipulation and use
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
function ConvertFrom-SQLDatabaseConnectionString { | |
[OutputType([PSCustomObject])] | |
[cmdletbinding()] | |
param( | |
[Parameter(mandatory, Valuefrompipeline)] | |
[string] | |
$ConnectionString | |
) | |
begin { | |
$hash = @{} | |
} | |
process { | |
$ConnectionString.Split(";") | % { | |
$d = $_.Split("=").Trim() | |
$hash.Add($d[0], $d[1]) | |
} | |
} | |
end { | |
return [PSCustomObject]$hash | |
} | |
} | |
function ConvertTo-SQLDatabaseConnectionString { | |
[OutputType([string])] | |
[cmdletbinding()] | |
param( | |
[Parameter(mandatory, Valuefrompipeline)] | |
[PSCustomObject] | |
$ConnectionStringObject | |
) | |
begin { | |
$Connstring = "" | |
} | |
process { | |
$ConnectionStringObject | get-member | ? MemberType -ne "method" | % { | |
$Connstring += [string]::Format("{0}={1};", $_.name, $ConnectionStringObject."$($_.Name)") | |
} | |
} | |
end { | |
return $Connstring | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment