Sunday, November 11, 2018

Test of Code Formatting

A good day
function MakeConnectionString{
    $connStr = New-Object System.Data.SqlClient.SqlConnectionStringBuilder
    $connStr['Data Source'] = $textboxInstance.Text
    $connStr['Initial Catalog'] = $textboxDatabase.Text
    if ($checkboxSSPI.Checked) {
        $connStr['Integrated Security'] = $true
        $textboxConnectionString.text = $connStr
    } else {
        if(Test-Path $env:APPDATA\PSDev\UserConfig.clixml){
            $user = Import-Clixml $env:APPDATA\PSDev\UserConfig.clixml
            $secPwd = $user.Password | ConvertTo-SecureString
            $credObject = New-Object System.Management.Automation.PSCredential($user.username, $secPwd)
            $connStr['User ID'] = $user.Username
            $connStr['Password'] = $credObject.GetNetworkCredential().Password
            $textboxConnectionString.text = $connStr
        }else{
            [System.Windows.Forms.MessageBox]::Show('You must either have a config file or edit the credential section to use SSPI','Credentials Required')
            $textboxConnectionString.Clear()
        }
    }
    Write-Host $connStr
}
ssssssssss
The end