-
Notifications
You must be signed in to change notification settings - Fork 3
/
PS_GUI_AD_Real_Name_Finder.ps1
55 lines (44 loc) · 2.15 KB
/
PS_GUI_AD_Real_Name_Finder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Wrote this as my first attempt at GUI POSH. This script accepts an Active Directory Users by SamAccontName and returns
#a users Real Name as listed in AD. The end result is a pop-up window with the users real name.
Function Get-RealName($SAMAccountName){
try {
(Get-ADUser $SAMAccountName -ErrorAction Stop).Name
}
catch {
Write-Output "Cannot find $SAMAccountName"
}
}
Add-Type -AssemblyName System.Windows.Forms
$GetActiveDirectoryUser = New-Object system.Windows.Forms.Form
$GetActiveDirectoryUser.Text = "GetActiveDirectoryUser"
$GetActiveDirectoryUser.TopMost = $true
$GetActiveDirectoryUser.Width = 450
$GetActiveDirectoryUser.Height = 150
$GetActiveDirectoryUser.Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSHOME + "\powershell.exe")
$textBox1_SAMAccountName = New-Object system.windows.Forms.TextBox
$textBox1_SAMAccountName.Width = 165
$textBox1_SAMAccountName.Height = 20
$textBox1_SAMAccountName.location = new-object system.drawing.point(137, 26)
$textBox1_SAMAccountName.Font = "Microsoft Sans Serif,10"
$GetActiveDirectoryUser.controls.Add($textBox1_SAMAccountName)
$button1_SAMAccountName = New-Object System.Windows.Forms.Button
$button1_SAMAccountName.Text = "Real Name"
$button1_SAMAccountName.Width = 100
$button1_SAMAccountName.Height = 30
$button1_SAMAccountName.Add_Click({
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup((Get-RealName -SamAccountName $textBox1_SAMAccountName.text), 0, "Real Name", 0x0)
})
$button1_SAMAccountName.location = new-object system.drawing.point(314, 23)
$button1_SAMAccountName.Font = "Microsoft Sans Serif,10"
$GetActiveDirectoryUser.controls.Add($button1_SAMAccountName)
$label1_SAMAccountName = New-Object system.windows.Forms.Label
$label1_SAMAccountName.Text = "SAMAccountName"
$label1_SAMAccountName.AutoSize = $true
$label1_SAMAccountName.Width = 25
$label1_SAMAccountName.Height = 10
$label1_SAMAccountName.location = new-object system.drawing.point(13, 27)
$label1_SAMAccountName.Font = "Microsoft Sans Serif,10"
$GetActiveDirectoryUser.controls.Add($label1_SAMAccountName)
[void] $GetActiveDirectoryUser.ShowDialog()
$GetActiveDirectoryUser.Dispose()