Ad script to WinForm

I got the following WinForm. How can i add commands to it?

The SamAccountName Field is for for the User/Group name. How do i catch this input?

The List shoud be a list with 2 entrys 1. user 2. group. This is the point where the user decides wether its a group or a user and would be awesome if i could somehow save that in a variable.

The Search Button should trigger the actual commands (A wildcard search for user or group).

DataGridView1 should display the output of the executed commands.

Hope someone can help me with that 🙂

The Executed code would be:

User: Get-ADUser -Filter "CN -like '*$find*' -or DisplayName -Like '*$find*' -or Description -Like '*$find*' -or DistinguishedName -Like '*$find*' -or Mail -Like '*$find*'" -Properties * | Sort-Object | Format-Table SamAccountName, displayName

Group: Get-ADGroup -Filter "SamAccountName -like '*$find*'" -Properties * | Sort-Object | Format-Table SamAccountName, Description

Add-Type -AssemblyName System.Windows.Forms


$Form = New-Object system.Windows.Forms.Form

$Form.ClientSize = ‘692,401’

$Form.text = “Form”

$Form.TopMost = $false

$SamAccountName = New-Object system.Windows.Forms.TextBox

$SamAccountName.multiline = $false

$SamAccountName.width = 100

$SamAccountName.height = 20

$SamAccountName.location = New-Object System.Drawing.Point(20,30)

$SamAccountName.Font = ‘Microsoft Sans Serif,10’

$List = New-Object system.Windows.Forms.ListView

$List.text = “listView”

$List.width = 80

$List.height = 30

$List.location = New-Object System.Drawing.Point(21,83)

$Search = New-Object system.Windows.Forms.Button

$Search.text = “Search”

$Search.width = 60

$Search.height = 30

$Search.location = New-Object System.Drawing.Point(143,30)

$Search.Font = ‘Microsoft Sans Serif,10’

$DataGridView1 = New-Object system.Windows.Forms.DataGridView

$DataGridView1.width = 675

$DataGridView1.height = 250

$DataGridView1.location = New-Object System.Drawing.Point(9,135)


$Form.ShowDialog() | Out-Null

submitted by /u/seyo_IV
[link] [comments]

Leave a Reply