Advertisement
Guest User

syncro_support_form

a guest
Mar 22nd, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ################################################  Powershell Support Form for Syncro  ##########################################################
  2. #################################  Made with instsructional assistance from Dan Stolts "ITProGuru"  ############################################
  3. ### https://channel9.msdn.com/Series/GuruPowerShell/GUI-Form-Using-PowerShell-Add-Panel-Label-Edit-box-Combo-Box-List-Box-CheckBox-and-More  ###
  4. ################################################################################################################################################
  5.  
  6. ################################################################################################################################################
  7. #############  Currently, this only works if you save this script to the local machine as .ps1 (ex. C:\itfolder\support_form.ps1), #############
  8. #############  make a .bat file with the same name, in the same folder (ex. C:\itfolder\support_form.bat), with this in            #############
  9. #############  the .bat file [@echo off powershell.exe -Command "& '%~dpn0.ps1'"] (Keep the quotes,don't use the brackets)         #############
  10. ################################################################################################################################################
  11.  
  12. Add-Type -AssemblyName WindowsBase, PresentationFramework, PresentationCore
  13. Add-Type -AssemblyName System.Windows.Forms
  14. Add-Type -AssemblyName System.Drawing
  15.  
  16. Import-Module $Env:SyncroModule -DisableNameChecking
  17. $hostname = "$env:computername"
  18. $date = (Get-Date)
  19.  
  20.  
  21. ######################  Enter Your Own Values below  ###########################
  22.  
  23.  
  24. ## Your Syncro sub-domain prefix
  25. $subdomain = 'YOUR_SUBDOMAIN_HERE'
  26.  
  27. ## Path to temporarily save your screenshot to
  28. $screenShotPath = 'C:\temp\Screenshots'
  29.  
  30. ## Title of your form
  31. $formTitle = 'IT Support Request Form'
  32.  
  33. ## Uses path to Syncro's default icon.  Change to point to your own icon
  34. $Icon = [system.drawing.icon]::ExtractAssociatedIcon('C:\ProgramData\Syncro\Images\logo.ico')
  35.  
  36. ## Alert Category if a user cancels a ticket
  37. $cancelledTicket = 'Ticket Cancelled'
  38.  
  39.  
  40. ############## Automatically Grab User's First and Last Name ###################
  41.  
  42.  
  43. $dom = $env:userdomain
  44. $usr = $env:username
  45. $currentUser = ([adsi]"WinNT://$dom/$usr,user").fullname
  46.  
  47.  
  48. ########################  Form Settings  ############################
  49.  
  50.  
  51. $form = New-Object System.Windows.Forms.Form
  52. $form.Icon = $Icon
  53. $form.Text = "$formTitle"
  54. $form.Size = New-Object System.Drawing.Size(475,475)
  55. $form.StartPosition = 'CenterScreen'
  56. $form.ControlBox = $False
  57. $form.BackColor = 'Ivory'
  58. $form.Font = [System.Drawing.Font]::new("Roboto", 10)
  59.  
  60.  
  61. ########################  Add Buttons  ##############################
  62.  
  63.  
  64. $buttonPanel = New-Object Windows.Forms.Panel  
  65.     $buttonPanel.Size = New-Object Drawing.Size @(350,40)
  66.     $buttonPanel.Dock = "Bottom"    
  67.     $cancelButton = New-Object Windows.Forms.Button  
  68.         $cancelButton.Top = $buttonPanel.Height - $cancelButton.Height - 10; $cancelButton.Left = $buttonPanel.Width - $cancelButton.Width - 10
  69.         $cancelButton.Text = "Cancel"
  70.         $cancelButton.DialogResult = "Cancel"
  71.         $cancelButton.Anchor = "Right"
  72.         $cancelButton.BackColor = "Pink"
  73.         $cancelButton.ForeColor = "Red"
  74.  
  75.     ## Create the OK button, which will anchor to the left of Cancel
  76.     $okButton = New-Object Windows.Forms.Button  
  77.         $okButton.Top = $cancelButton.Top ; $okButton.Left = $cancelButton.Left - $okButton.Width - 5
  78.         $okButton.Text = "Submit"
  79.         $okButton.DialogResult = "Ok"
  80.         $okButton.Anchor = "Right"
  81.         $okButton.BackColor = "MintCream"
  82.         $okButton.Enabled = $False
  83.         # $okButton.Add_Click = ({ $x = $textSubject.Text; $form.Close() })
  84.  
  85.  
  86.     ## Add the buttons to the button panel
  87.     $buttonPanel.Controls.Add($okButton)
  88.     $buttonPanel.Controls.Add($cancelButton)
  89.  
  90. ## Add the button panel to the form
  91. $form.Controls.Add($buttonPanel)
  92.  
  93. ## Set Default actions for the buttons
  94. $form.AcceptButton = $okButton          # ENTER = Ok
  95. $form.CancelButton = $cancelButton      # ESCAPE = Cancel
  96.  
  97.  
  98. ##############################  Labels  ##############################
  99.  
  100.  
  101. $labelHost = New-Object System.Windows.Forms.Label
  102. $labelHost.Location = New-Object System.Drawing.Point(10,20)
  103. $labelHost.Size = New-Object System.Drawing.Size(90,20)
  104. $labelHost.Text = 'Device'
  105. $labelHost.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
  106. $form.Controls.Add($labelHost)
  107.  
  108. $labelSubject = New-Object System.Windows.Forms.Label
  109. $labelSubject.Location = New-Object System.Drawing.Point(10,60)
  110. $labelSubject.Size = New-Object System.Drawing.Size(90,20)
  111. $labelSubject.Text = 'Subject'
  112. $labelSubject.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
  113. $labelSubject.ForeColor = 'Red'
  114. $form.Controls.Add($labelSubject)
  115.  
  116. $labelDesc = New-Object System.Windows.Forms.Label
  117. $labelDesc.Location = New-Object System.Drawing.Point(10,100)
  118. $labelDesc.Size = New-Object System.Drawing.Size(90,40)
  119. $labelDesc.Text = 'Description'
  120. $labelDesc.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
  121. $labelDesc.ForeColor = 'Red'
  122. $form.Controls.Add($labelDesc)
  123.  
  124. $labelName = New-Object System.Windows.Forms.Label
  125. $labelName.Location = New-Object System.Drawing.Point(10,200)
  126. $labelName.Size = New-Object System.Drawing.Size(90,20)
  127. $labelName.Text = 'Name'
  128. $labelName.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
  129. $form.Controls.Add($labelName)
  130.  
  131. $labelEmail = New-Object System.Windows.Forms.Label
  132. $labelEmail.Location = New-Object System.Drawing.Point(10,240)
  133. $labelEmail.Size = New-Object System.Drawing.Size(90,40)
  134. $labelEmail.Text = 'Email'
  135. $labelEmail.Font = [System.Drawing.Font]::new("Roboto", 10, [System.Drawing.FontStyle]::Bold)
  136. $form.Controls.Add($labelEmail)
  137.  
  138.  
  139. ########################  Input Fields  ########################
  140.  
  141.  
  142. $textHost = New-Object System.Windows.Forms.TextBox
  143. $textHost.Location = New-Object System.Drawing.Point(120,20)
  144. $textHost.Size = New-Object System.Drawing.Size(120,20)
  145. $textHost.ReadOnly = $True
  146. $textHost.Text = "$Hostname"
  147. $form.Controls.Add($textHost)
  148.  
  149. $textSubject = New-Object System.Windows.Forms.TextBox
  150. $textSubject.Location = New-Object System.Drawing.Point(120,60)
  151. $textSubject.Size = New-Object System.Drawing.Size(330,20)
  152. $textSubject.MaxLength = 255
  153. $form.Controls.Add($textSubject)
  154.  
  155. $textDesc = New-Object System.Windows.Forms.TextBox
  156. $textDesc.Multiline = $True
  157. $textDesc.WordWrap = $True
  158. $textDesc.Location = New-Object System.Drawing.Point(120,100)
  159. $textDesc.Size = New-Object System.Drawing.Size(330,80)
  160. $textDesc.MaxLength = 1000
  161. $textDesc.ScrollBars = 3
  162. $form.Controls.Add($textDesc)
  163.  
  164. $textName = New-Object System.Windows.Forms.TextBox
  165. $textName.Location = New-Object System.Drawing.Point(120,200)
  166. $textName.Size = New-Object System.Drawing.Size(330,20)
  167. $textName.Text = "$currentUser"
  168. $form.Controls.Add($textName)
  169.  
  170. $textEmail = New-Object System.Windows.Forms.TextBox
  171. $textEmail.Location = New-Object System.Drawing.Point(120,240)
  172. $textEmail.Size = New-Object System.Drawing.Size(330,20)
  173. $form.Controls.Add($textEmail)
  174.  
  175.  
  176. ##################  Form Field Validation  ######################
  177.  
  178.  
  179. $textSubject.add_TextChanged -and $textDesc.add_TextChanged({ Checkfortext })
  180.  
  181. function Checkfortext
  182. {
  183.     if ($textSubject.Text.Length -ne 0 -and $textDesc.Text.Length -ne 0)
  184.     {
  185.         $okButton.Enabled = $true
  186.         $labelSubject.Text = 'Subject'
  187.         $labelSubject.ForeColor = 'Black'
  188.         $labelDesc.Text = 'Description'
  189.         $labelDesc.ForeColor = 'Black'
  190.     }
  191.     else
  192.     {
  193.         $okButton.Enabled = $false
  194.         $labelSubject.Text = 'Subject *'
  195.         $labelSubject.ForeColor = 'Red'
  196.         $labelDesc.Text = 'Description *'
  197.         $labelDesc.ForeColor = 'Red'
  198.     }
  199. }
  200.  
  201. #################################################################
  202.  
  203. $form.Topmost = $true
  204.  
  205. $form.Add_Shown({$textSubject.Select()})
  206.  
  207. $result = $form.ShowDialog()
  208.  
  209. ## Output text from entered fields
  210. $subjectEntry = $textSubject.Text
  211. $descEntry = $textDesc.Text
  212. $nameEntry = $textName.Text
  213. $emailEntry = $textEmail.Text
  214.  
  215. if ($result -eq [System.Windows.Forms.DialogResult]::OK)
  216.     {
  217.         #####################  CURRENTLY ONLY ABLE TO UPLOAD TO ASSET.  #####################
  218.         ########  UNCOMMENT 'Upload-File' TO ENABLE UPLOADING SCREENSHOT TO ASSET  ##########
  219.        
  220.         ## Take Screenshot
  221.         Get-ScreenCapture -FullFileName "$screenShotPath\screenshot.jpg"
  222.         #Upload-File -Subdomain "$subdomain" -FilePath "$screenShotPath\screenshot.jpg"
  223.  
  224.         ## Create ticket
  225.         $ticketOutput = Create-Syncro-Ticket -Subdomain "$subdomain" -Subject "$subjectEntry - $emailEntry" -IssueType "Submission" -Status "New"
  226.  
  227.         ## Write the output of the ticket to console, assign it a varaible
  228.         Write-Host $ticketOutput
  229.  
  230.         ## Grab ticket number from the output
  231.         $ticketNumber = $ticketOutput.ticket.number
  232.  
  233.         ## Add a ticket comment
  234.         Create-Syncro-Ticket-Comment -Subdomain "$subdomain" -TicketIdOrNumber $ticketNumber -Subject "Issue" -Body "Submitted by $nameEntry $emailEntry - $descEntry" -Hidden $False
  235.        
  236.         ## Delete screenshot
  237.         Remove-Item "$screenShotPath\screenshot.jpg"
  238.     }
  239. else
  240.     {
  241.         Write-Host $cancelledTicket
  242.  
  243.         ## Optionally write cancelled ticket event to Asset as Alert
  244.         ## Uncomment next line to activate
  245.         # Rmm-Alert -Category "$cancelledTicket" -Body "User $nameEntry $emailEntry Cancelled a Support Request"
  246.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement