Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

String zu einem Secure string konventiren

$
0
0

Hallo Zusammen, ich mache ein kleines Skript mit einem Gui.
Bei einer Textbox wo ich ein Passwort eingeben, kommt immer ich kann den string nicht ihn ein securesafe konventieren


Add-Type -AssemblyName System.Windows.Forms


#### GUI selber
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "PC-Infos"
$Form.TopMost = $true
$Form.Width = 612
$Form.Height = 418

#### Textfeld

$listView1 = New-Object system.windows.Forms.ListView
$listView1.Text = "listView"
$listView1.Width = 398
$listView1.Height = 167
$listView1.location = new-object system.drawing.point(74,184)
$Form.controls.Add($listView1)

#### Benutzer hinzufügen Button

$button1 = New-Object system.windows.Forms.Button
$button1.Text = "Benutzer hinzufügen"
$button1.Width = 147
$button1.Height = 32
$button1.location = new-object system.drawing.point(75,44)
$button1.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($button1)
$button1.Add_Click({
   $form = New-Object System.Windows.Forms.Form

   #### Titel

$form.Text = 'Automatisierung für Benutzer anlegen'
$form.Size = New-Object System.Drawing.Size(500,400)
$form.StartPosition = 'CenterScreen'

   #### OK-Button

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(25,325)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$OKButton.Add_Click({$x=$TextBox.Text;$Form.Close})
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

  #### Cancel-Button

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(120,325)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$CancelButton.Add_Click({$Form.Close()})
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

  #### Abfrage 1

$label1 = New-Object System.Windows.Forms.Label
$label1.Location = New-Object System.Drawing.Point(10,20)
$label1.Size = New-Object System.Drawing.Size(280,20)
$label1.Text = 'Benutzername:'
$form.Controls.Add($label1)

$textBox1 = New-Object System.Windows.Forms.TextBox
$textBox1.Location = New-Object System.Drawing.Point(10,40)
$textBox1.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox1)

  #### Abfrage 2

$label2 = New-Object System.Windows.Forms.Label
$label2.Location = New-Object System.Drawing.Point(10,80)
$label2.Size = New-Object System.Drawing.Size(280,20)
$label2.Text = 'Passwort:'
$form.Controls.Add($label2)

$textBox2 = New-Object System.Windows.Forms.TextBox
$textBox2.Location = New-Object System.Drawing.Point(10,100)
$textBox2.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox2)

  #### Abfrage 3

$label3 = New-Object System.Windows.Forms.Label
$label3.Location = New-Object System.Drawing.Point(10,140)
$label3.Size = New-Object System.Drawing.Size(280,20)
$label3.Text = 'Passwort wiederholen:'
$form.Controls.Add($label3)

$textBox3 = New-Object System.Windows.Forms.TextBox
$textBox3.Location = New-Object System.Drawing.Point(10,160)
$textBox3.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox3)

  #### Abfrage 4

$label4 = New-Object System.Windows.Forms.Label
$label4.Location = New-Object System.Drawing.Point(10,200)
$label4.Size = New-Object System.Drawing.Size(280,20)
$label4.Text = 'Vollständiger Name:'
$form.Controls.Add($label4)

$textBox4 = New-Object System.Windows.Forms.TextBox
$textBox4.Location = New-Object System.Drawing.Point(10,220)
$textBox4.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox4)

  #### Abfrage 5

$label5 = New-Object System.Windows.Forms.Label
$label5.Location = New-Object System.Drawing.Point(10,200)
$label5.Size = New-Object System.Drawing.Size(280,20)
$label5.Text = 'Beschreibung:'
$form.Controls.Add($label5)

$textBox5 = New-Object System.Windows.Forms.TextBox
$textBox5.Location = New-Object System.Drawing.Point(10,220)
$textBox5.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($textBox5)

 #### Abfrage 6

#$label = New-Object System.Windows.Forms.Label
#$label.Location = New-Object System.Drawing.Point(10,200)
#$label.Size = New-Object System.Drawing.Size(280,20)
#$label.Text = get-localuser
#$form.Controls.Add($label)

$form.Topmost = $true

$form.Add_Shown({$textBox1.Select()})

$result = $form.ShowDialog()

if ($OKButton.Add_Click)
{
    if($textBox2.Text -eq $textBox3.Text){
    New-LocalUser -Name $textBox1.Text -Password $textBox2.Text -FullName $textBox4.Text -Description $textBox5.Text
    } else {
    $label6 = New-Object System.Windows.Forms.Label
    $label6.Location = New-Object System.Drawing.Point(240,325)
    $label6.Size = New-Object System.Drawing.Size(280,20)
    $label6.Text = 'Das Passwort stimmt nicht überrein'
    $form.Controls.Add($label6)
    }
}
})

####### Benutzer löschen Button

$button2 = New-Object system.windows.Forms.Button
$button2.Text = "Benutzer löschen"
$button2.Width = 147
$button2.Height = 32
$button2.location = new-object system.drawing.point(314,44)
$button2.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($button2)       
###### Benutzer sehen Button       
$button3 = New-Object system.windows.Forms.Button
$button3.Text = "Benutzer sehen"
$button3.Width = 147
$button3.Height = 32
$button3.location = new-object system.drawing.point(75,94)
$button3.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($button3)  

###### Exit Button
$button4 = New-Object system.windows.Forms.Button
$button4.Text = "Exit"
$button4.Width = 147
$button4.Height = 32
$button4.location = new-object system.drawing.point(313,93)
$button4.Font = "Microsoft Sans Serif,10"
$Form.controls.Add($button4)
$button4.Add_Click({
    $form.Close()
})


#### damit das GUI angezeigt wird.
 [void]$Form.ShowDialog()

 $Form.Dispose()

 

Viewing all articles
Browse latest Browse all 2314


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