mardi 17 novembre 2015

How to place content in variable with wpf Checkbox and powershell

I'm trying to place an ip in a variable when i make the checkbox checked and use this variable as the ip address in Invoke-SQLCMD. It seems that the content of the $DB00 stays empty whatever i do.

       $window.DB00.add_Checked(
                {
                $DB00 = '192.168.1.1'

                    [System.Object]$sender = $args[0]
                    [System.Windows.RoutedEventArgs]$e = $args[1]   

                }
    )
        $window.DB00.add_Unchecked(
                {
                $DB00 = $null

                #Get-ChildItem variable:\DB00  
                  #Remove-Item variable:\DB00
                    [System.Object]$sender = $args[0]
                    [System.Windows.RoutedEventArgs]$e = $args[1]   

                }
    )
        $window.DB00.add_Indeterminate(
                {
                $DB00 = $null

            [System.Object]$sender = $args[0]
            [System.Windows.RoutedEventArgs]$e = $args[1]   

                }
    )


    #Collect Input fields#
    $window.Button.add_Click(
        {   
            $UserName = $window.UserName.Text.ToString()
            $PassWord = $window.PassWord.Text.ToString()
            $ServerAddress = $DB00
            $DataBase = $window.DataBase.Text.ToString()
            $SQLQuery = $window.Query.Text.ToString()
            Invoke-Sqlcmd -AbortOnError -Username $UserName -Password $PassWord -Database $DataBase -Query $SQLQuery -QueryTimeout 30 -ServerInstance $ServerAddress  | Out-GridView -Title $DataBase
            [System.Object]$sender = $args[0]
            [System.Windows.RoutedEventArgs]$e = $args[1]   

        }

    ) 




Aucun commentaire:

Enregistrer un commentaire