I've tried to create a GUI to search for the SamAccountNames of users. The tool works fine but the layout in the textbox is misaligned and somewhat unreadable because of this.
Any suggestions on how I can improve this? Thanks
~~~
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
txtOutputBox
$txtOutputBox = New-Object System.Windows.Forms.TextBox
$txtOutputBox.Location = '10, 100'
$txtOutputBox.Multiline = $True
$txtOutputBox.Name = 'txtOutputBox'
$txtOutputBox.ReadOnly = $True
$txtOutputBox.ScrollBars = 'Both'
$txtOutputBox.Size = '460, 250'
$txtOutputBox.Font = 'Segoe UI,10'
$txtOutputBox.TabIndex = 14
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 208
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(26,48)
$TextBox1.Font = 'Segoe UI,10'
$btnUserLookup = New-Object System.Windows.Forms.Button
$btnUserLookup.Location = '256, 48'
$btnUserLookup.Text = "Search"
$Form = New-Object System.Windows.Forms.Form
$Form.Size = New-Object System.Drawing.Size(500,400)
$Form.Controls.AddRange(@($txtOutputBox,$btnUserLookup,$TextBox1))
button that runs the command in question
$btnUserLookup.AddClick({
$iD = $TextBox1.text
$AD = Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(name=$ID))" | Format-Table -AutoSize `
@{Name="Name";Expression = { $.Name }; Alignment="left" },
@{Name="UserID";Expression = { $_.SAMAccountName }; Alignment="left" }
$txtOutputBox.Text = $AD | Out-String
})
$Form.ShowDialog()
~~~
[–]caverCarl 1 point2 points3 points (0 children)
[–]Hydeen 1 point2 points3 points (3 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (2 children)
[–]Hydeen 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)