Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Simple windows form with a combobox and radio

$
0
0

Hi,

Sorry, but i'm newbie in PS and my english so bad(

I try create a simple windows form with a combobox and radio for easy select credentials and connect to MS online services.

It must import from csv Username and pass, after it i'm select param(from radio) to connect, username(from combobox) and after click button must be running powershell console.

Sorry for my bad english(

CSV file like:

Username,Password
user1@test.onmicrosoft.com,13456
user2@1111.onmicrosoft.com,654321

Script:

Add-Type -assembly System.Windows.Forms

$main_form = New-Object System.Windows.Forms.Form
$main_form.Text ='Connect'
$main_form.Width = 100
$main_form.Height = 100
$main_form.AutoSize = $true
$main_form.TopMost = $true

$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Select service:"
$Label.Location  = New-Object System.Drawing.Point(10,10)
$Label.AutoSize = $true
$main_form.Controls.Add($Label)

$RadioButton = New-Object System.Windows.Forms.RadioButton
$RadioButton.Location  = New-Object System.Drawing.Point(10,30)
$RadioButton.Text = 'MSO'
$RadioButton.AutoSize = $true
$main_form.Controls.Add($RadioButton)

$RadioButton1 = New-Object System.Windows.Forms.RadioButton
$RadioButton1.Location  = New-Object System.Drawing.Point(10,50)
$RadioButton1.Text = 'Azure'
$RadioButton1.AutoSize = $true
$main_form.Controls.Add($RadioButton1)

$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList

$ComboBox.DataSource = @{}
import-csv C:\Users.csv -delimiter "," | ForEach-Object {
    $ComboBox.Items.Add($_.username)
    $ComboBox.DataSource.Add($_.username,$_.pass)
}

$ComboBox.Location  = New-Object System.Drawing.Point(10,80)
$ComboBox.Width = 200
$main_form.Controls.Add($ComboBox)

$button = New-Object System.Windows.Forms.Button
$button.Text = 'Connect'
$button.Location = New-Object System.Drawing.Point(70,120)
$main_form.Controls.Add($button)

$button.Add_Click({
$x = import-csv C:\azure\moduls\Login\cred\Users.csv -delimiter "," | ? { $_.username -eq $combobox.Text } | Select -first 1
$sel = $ComboBox.SelectedItem.ToString(); $main_form.Close()
})
$main_form.ShowDialog()


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>