-
Notifications
You must be signed in to change notification settings - Fork 36
/
Show-AccountSID.ps1
132 lines (117 loc) · 5.57 KB
/
Show-AccountSID.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<# This form was created using POSHGUI.com a free online gui designer for PowerShell
WrittenBy: http://vcloud-lab.com
.NAME
SID to Account
Account to SID
#>
#Add-Type -AssemblyName System.Windows.Forms
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Application]::EnableVisualStyles()
function Get-SID {
try {
$LocalAccount = New-Object System.Security.Principal.NTAccount(($InputBox.Text).trim()) -ErrorAction Stop
$LocalSID = $LocalAccount.Translate([System.Security.Principal.SecurityIdentifier])
$OutputResult.Text = $LocalSID.Value
}
catch {
[System.Windows.Forms.MessageBox]::Show("Typed Domain\AccountName not valid", "Invalid details")
$OutputResult.Text = ''
}
}
function Get-Account {
try {
$SID = New-Object System.Security.Principal.SecurityIdentifier(($InputBox.Text).trim()) -ErrorAction Stop
$DomainAccount = $SID.Translate([System.Security.Principal.NTAccount])
$OutputResult.Text = $DomainAccount.Value
}
catch {
[System.Windows.Forms.MessageBox]::Show("Typed SID is not valid", "Invalid details")
$OutputResult.Text = ''
}
}
#region begin GUI{
$Tooltip = New-Object System.Windows.Forms.ToolTip
$ShowHelp = {
Switch ($this.name) {
'InputBox' {$Tip = "If local checked don't provide domainname"; Break}
'SidToUser' {$Tip = 'Type Valid Domain\UserName'; Break}
'UserToSid' {$Tip = 'Type Valid User SID'; Break}
'LocalCheckBox' {$Tip = "If local checked don't provide domainname"; Break}
}
$Tooltip.SetToolTip($this,$Tip)
}
$vcloudlabform = New-Object system.Windows.Forms.Form
$vcloudlabform.ClientSize = '396,172'
$vcloudlabform.text = "SID to Account and Vice Versa"
$vcloudlabform.TopMost = $false
$InputBox = New-Object system.Windows.Forms.TextBox
$InputBox.Name = 'InputBox'
$InputBox.multiline = $false
$InputBox.width = 366
$InputBox.height = 20
$InputBox.location = New-Object System.Drawing.Point(8,19)
$InputBox.Font = 'Microsoft Sans Serif,10'
$InputBoxWaterMark = 'Type valid User, Group with Domain or SID'
$InputBox.ForeColor = 'LightGray'
$InputBox.Text = $InputBoxWaterMark
$InputBox.add_MouseHover($ShowHelp)
$InputBox.add_TextChanged({$InputBox.ForeColor = 'Black'})
$SidToAccount = New-Object system.Windows.Forms.Button
$SidToAccount.Name = 'SidToUser'
$SidToAccount.text = 'SID-To-Account'
$SidToAccount.width = 115
$SidToAccount.height = 30
$SidToAccount.location = New-Object System.Drawing.Point(10,98)
$SidToAccount.Font = 'Microsoft Sans Serif,10'
$SidToAccount.add_MouseHover($ShowHelp)
$SidToAccount.add_Click({Show-SIDToAccount})
$AccountToSid = New-Object system.Windows.Forms.Button
$AccountToSid.Name = 'UserToSid'
$AccountToSid.text = 'Account-To-SID'
$AccountToSid.width = 115
$AccountToSid.height = 30
$AccountToSid.location = New-Object System.Drawing.Point(127,98)
$AccountToSid.Font = 'Microsoft Sans Serif,10'
$AccountToSid.add_MouseHover($ShowHelp)
$AccountToSid.add_Click({Show-AccountToSID})
$OutputResult = New-Object system.Windows.Forms.TextBox
$OutputResult.Name = 'OutputResult'
$OutputResult.multiline = $false
$OutputResult.width = 366
$OutputResult.height = 20
$OutputResult.location = New-Object System.Drawing.Point(8,53)
$OutputResult.Font = 'Microsoft Sans Serif,10'
$OutputResult.ReadOnly = $true
$Site = New-Object system.Windows.Forms.LinkLabel
$Site.Name = 'Site'
$Site.text = "http://vcloud-lab.com"
$Site.LinkColor = "#0074A2"
$Site.ActiveLinkColor = "#114C7F"
$Site.AutoSize = $true
$Site.width = 25
$Site.height = 10
$Site.location = New-Object System.Drawing.Point(260,154)
$Site.Font = 'Microsoft Sans Serif,10'
$Site.add_Click({[system.Diagnostics.Process]::start('http://vcloud-lab.com')})
$vcloudlabform.controls.AddRange(@($InputBox,$OutputResult,$SidToAccount,$AccountToSid,$Site))
#region gui events {
function Show-AccountToSID {
if (($InputBox.Text -eq $InputBoxWaterMark) -or ($InputBox.Text -eq '')) {
[System.Windows.Forms.MessageBox]::Show("Please type valid Domain\Account", "Textbox empty")
}
else {
Get-SID
}
}
function Show-SIDToAccount {
if (($InputBox.Text -eq $InputBoxWaterMark) -or ($InputBox.Text -eq '')) {
[System.Windows.Forms.MessageBox]::Show("Please type valid SID", "Textbox empty")
}
else {
Get-Account
}
}
#endregion events }
#endregion GUI }
[void]$vcloudlabform.ShowDialog()