Menu

[55dae9]: / sandbox / SyncroSupportForm.ps1  Maximize  Restore  History

Download this file

239 lines (193 with data), 9.8 kB

  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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
################################################ Powershell Support Form for Syncro ##########################################################
################################# Made with instsructional assistance from Dan Stolts "ITProGuru" ############################################
### https://channel9.msdn.com/Series/GuruPowerShell/GUI-Form-Using-PowerShell-Add-Panel-Label-Edit-box-Combo-Box-List-Box-CheckBox-and-More ###
################################################################################################################################################
Add-Type -AssemblyName WindowsBase, PresentationFramework, PresentationCore
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Import-Module $Env:SyncroModule
$hostname = "$env:computername"
$date = (Get-Date)
################################################################################
######################## Enter Your Own Variables ############################
################################################################################
## Your Syncro sub-domain prefix
$subdomain = 'YOUR_SUBDOMAINDOMAIN_HERE'
## Path to temporarily save your screenshot to
$screenShotPatch = 'C:\temp\Screenshots'
## Title of your form
$formTitle = 'IT Support Request Form'
## Uses path to Syncro's default icon. Change to point to your own icon
$Icon = [system.drawing.icon]::ExtractAssociatedIcon('C:\ProgramData\Syncro\Images\logo.ico')
## Alert Category if a user cancels a ticket
$cancelledTicket = 'Ticket Cancelled'
################################################################################
######################## Grab User's First and Last Name #######################
################################################################################
$dom = $env:userdomain
$usr = $env:username
$currentUser = ([adsi]"WinNT://$dom/$usr,user").fullname
#####################################################################
######################## Form Settings ############################
#####################################################################
$form = New-Object System.Windows.Forms.Form
$form.Icon = $Icon
$form.Text = "$formTitle"
$form.Size = New-Object System.Drawing.Size(475,475)
$form.StartPosition = 'CenterScreen'
$form.ControlBox = $False
$form.BackColor = 'Ivory'
$form.Font = [System.Drawing.Font]::new("Roboto", 10)
#####################################################################
######################## Add Buttons ##############################
#####################################################################
$buttonPanel = New-Object Windows.Forms.Panel
$buttonPanel.Size = New-Object Drawing.Size @(350,40)
$buttonPanel.Dock = "Bottom"
$cancelButton = New-Object Windows.Forms.Button
$cancelButton.Top = $buttonPanel.Height - $cancelButton.Height - 10; $cancelButton.Left = $buttonPanel.Width - $cancelButton.Width - 10
$cancelButton.Text = "Cancel"
$cancelButton.DialogResult = "Cancel"
$cancelButton.Anchor = "Right"
$cancelButton.BackColor = "Pink"
$cancelButton.ForeColor = "Red"
## Create the OK button, which will anchor to the left of Cancel
$okButton = New-Object Windows.Forms.Button
$okButton.Top = $cancelButton.Top ; $okButton.Left = $cancelButton.Left - $okButton.Width - 5
$okButton.Text = "Submit"
$okButton.DialogResult = "Ok"
$okButton.Anchor = "Right"
$okButton.BackColor = "MintCream"
$okButton.Enabled = $False
# $okButton.Add_Click = ({ $x = $textSubject.Text; $form.Close() })
## Add the buttons to the button panel
$buttonPanel.Controls.Add($okButton)
$buttonPanel.Controls.Add($cancelButton)
## Add the button panel to the form
$form.Controls.Add($buttonPanel)
## Set Default actions for the buttons
$form.AcceptButton = $okButton # ENTER = Ok
$form.CancelButton = $cancelButton # ESCAPE = Cancel
######################################################################
############################## Labels ##############################
######################################################################
$labelHost = New-Object System.Windows.Forms.Label
$labelHost.Location = New-Object System.Drawing.Point(10,20)
$labelHost.Size = New-Object System.Drawing.Size(90,20)
$labelHost.Text = 'Device'
$labelHost.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($labelHost)
$labelSubject = New-Object System.Windows.Forms.Label
$labelSubject.Location = New-Object System.Drawing.Point(10,60)
$labelSubject.Size = New-Object System.Drawing.Size(90,20)
$labelSubject.Text = 'Subject'
$labelSubject.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
$labelSubject.ForeColor = 'Red'
$form.Controls.Add($labelSubject)
$labelDesc = New-Object System.Windows.Forms.Label
$labelDesc.Location = New-Object System.Drawing.Point(10,100)
$labelDesc.Size = New-Object System.Drawing.Size(90,40)
$labelDesc.Text = 'Description'
$labelDesc.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
$labelDesc.ForeColor = 'Red'
$form.Controls.Add($labelDesc)
$labelName = New-Object System.Windows.Forms.Label
$labelName.Location = New-Object System.Drawing.Point(10,200)
$labelName.Size = New-Object System.Drawing.Size(90,20)
$labelName.Text = 'Name'
$labelName.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($labelName)
$labelEmail = New-Object System.Windows.Forms.Label
$labelEmail.Location = New-Object System.Drawing.Point(10,240)
$labelEmail.Size = New-Object System.Drawing.Size(90,40)
$labelEmail.Text = 'Email'
$labelEmail.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
$form.Controls.Add($labelEmail)
################################################################
######################## Input Fields ########################
################################################################
$textHost = New-Object System.Windows.Forms.TextBox
$textHost.Location = New-Object System.Drawing.Point(120,20)
$textHost.Size = New-Object System.Drawing.Size(120,20)
$textHost.ReadOnly = $True
$textHost.Text = "$Hostname"
$form.Controls.Add($textHost)
$textSubject = New-Object System.Windows.Forms.TextBox
$textSubject.Location = New-Object System.Drawing.Point(120,60)
$textSubject.Size = New-Object System.Drawing.Size(330,20)
$textSubject.MaxLength = 255
$form.Controls.Add($textSubject)
$textDesc = New-Object System.Windows.Forms.TextBox
$textDesc.Multiline = $True
$textDesc.WordWrap = $True
$textDesc.Location = New-Object System.Drawing.Point(120,100)
$textDesc.Size = New-Object System.Drawing.Size(330,80)
$textDesc.MaxLength = 1000
$textDesc.ScrollBars = 3
$form.Controls.Add($textDesc)
$textName = New-Object System.Windows.Forms.TextBox
$textName.Location = New-Object System.Drawing.Point(120,200)
$textName.Size = New-Object System.Drawing.Size(330,20)
$textName.Text = "$currentUser"
$form.Controls.Add($textName)
$textEmail = New-Object System.Windows.Forms.TextBox
$textEmail.Location = New-Object System.Drawing.Point(120,240)
$textEmail.Size = New-Object System.Drawing.Size(330,20)
$form.Controls.Add($textEmail)
#################################################################
################## Form Field Validation ######################
#################################################################
$textSubject.add_TextChanged -and $textDesc.add_TextChanged({ Checkfortext })
function Checkfortext
{
if ($textSubject.Text.Length -ne 0 -and $textDesc.Text.Length -ne 0)
{
$okButton.Enabled = $true
$labelSubject.Text = 'Subject'
$labelSubject.ForeColor = 'Black'
$labelDesc.Text = 'Description'
$labelDesc.ForeColor = 'Black'
}
else
{
$okButton.Enabled = $false
$labelSubject.Text = 'Subject *'
$labelSubject.ForeColor = 'Red'
$labelDesc.Text = 'Description *'
$labelDesc.ForeColor = 'Red'
}
}
#################################################################
$form.Topmost = $true
$form.Add_Shown({$textSubject.Select()})
$result = $form.ShowDialog()
## Output text from entered fields
$subjectEntry = $textSubject.Text
$descEntry = $textDesc.Text
$nameEntry = $textName.Text
$emailEntry = $textEmail.Text
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
##################### CURRENTLY ONLY ABLE TO UPLOAD TO ASSET. #####################
######## UNCOMMENT 'Upload-File' TO ENABLE UPLOADING SCREENSHOT TO ASSET ##########
## Take Screenshot
Get-ScreenCapture -FullFileName "$screenShotPath\screenshot.jpg"
# Upload-File -Subdomain "$subdomain" -FilePath "$screenShotPath\screenshot.jpg"
## Create ticket
$ticketOutput = Create-Syncro-Ticket -Subdomain "$subdomain" -Subject "$subjectEntry - $emailEntry" -IssueType "Submission" -Status "New"
## Write the output of the ticket to console, assign it a varaible
Write-Host $ticketOutput
## Grab ticket number from the output
$ticketNumber = $ticketOutput.ticket.number
## Add a ticket comment
Create-Syncro-Ticket-Comment -Subdomain "$subdomain" -TicketIdOrNumber $ticketNumber -Subject "Issue" -Body "Submitted by $nameEntry $emailEntry - $descEntry" -Hidden $False
## Delete screenshot
Remove-Item "$screenShotPath\screenshot.jpg"
}
else
{
Write-Host $cancelledOutput
## Optionally write cancelled ticket event to Asset as Alert
## Uncomment to activate
Rmm-Alert -Category "$cancelledTicket" -Body "User $nameEntry $emailEntry Cancelled a Support Request"
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.