wizard210

Simple Helpdesk Form

Apr 13th, 2018
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <# This form was created using POSHGUI.com  a free online gui designer for PowerShell
  2. .NAME
  3.     Ticket Request
  4. #>
  5.  
  6. Add-Type -AssemblyName System.Windows.Forms
  7. [System.Windows.Forms.Application]::EnableVisualStyles()
  8.  
  9. #region begin GUI{
  10.  
  11. $Form                            = New-Object system.Windows.Forms.Form
  12. $Form.ClientSize                 = '545,400'
  13. $Form.text                       = "Ticket Request Form"
  14. $Form.TopMost                    = $false
  15.  
  16. $Label1                          = New-Object system.Windows.Forms.Label
  17. $Label1.text                     = "Email"
  18. $Label1.AutoSize                 = $true
  19. $Label1.width                    = 25
  20. $Label1.height                   = 10
  21. $Label1.location                 = New-Object System.Drawing.Point(25,78)
  22. $Label1.Font                     = 'Microsoft Sans Serif,10'
  23.  
  24. $Label2                          = New-Object system.Windows.Forms.Label
  25. $Label2.text                     = "Request Type"
  26. $Label2.AutoSize                 = $true
  27. $Label2.width                    = 25
  28. $Label2.height                   = 10
  29. $Label2.location                 = New-Object System.Drawing.Point(25,114)
  30. $Label2.Font                     = 'Microsoft Sans Serif,10'
  31.  
  32. $Label3                          = New-Object system.Windows.Forms.Label
  33. $Label3.text                     = "Subject"
  34. $Label3.AutoSize                 = $true
  35. $Label3.width                    = 25
  36. $Label3.height                   = 10
  37. $Label3.location                 = New-Object System.Drawing.Point(25,152)
  38. $Label3.Font                     = 'Microsoft Sans Serif,10'
  39.  
  40. $Label4                          = New-Object system.Windows.Forms.Label
  41. $Label4.text                     = "Description"
  42. $Label4.AutoSize                 = $true
  43. $Label4.width                    = 25
  44. $Label4.height                   = 10
  45. $Label4.location                 = New-Object System.Drawing.Point(25,195)
  46. $Label4.Font                     = 'Microsoft Sans Serif,10'
  47.  
  48. $TextBox1                        = New-Object system.Windows.Forms.TextBox
  49. $TextBox1.multiline              = $false
  50. $TextBox1.width                  = 100
  51. $TextBox1.height                 = 20
  52. $TextBox1.location               = New-Object System.Drawing.Point(-12,-19)
  53. $TextBox1.Font                   = 'Microsoft Sans Serif,10'
  54.  
  55. $email                           = New-Object system.Windows.Forms.TextBox
  56. $email.multiline                 = $false
  57. $email.width                     = 267
  58. $email.height                    = 20
  59. $email.location                  = New-Object System.Drawing.Point(122,74)
  60. $email.Font                      = 'Microsoft Sans Serif,10'
  61.  
  62. $subject                         = New-Object system.Windows.Forms.TextBox
  63. $subject.multiline               = $false
  64. $subject.width                   = 267
  65. $subject.height                  = 20
  66. $subject.location                = New-Object System.Drawing.Point(122,147)
  67. $subject.Font                    = 'Microsoft Sans Serif,10'
  68.  
  69. $description                        = New-Object system.Windows.Forms.TextBox
  70. $description.multiline              = $true
  71. $description.width                  = 267
  72. $description.height                 = 163
  73. $description.location               = New-Object System.Drawing.Point(122,190)
  74. $description.Font                   = 'Microsoft Sans Serif,10'
  75.  
  76. $request                         = New-Object system.Windows.Forms.ComboBox
  77. $request.width                   = 267
  78. $request.height                  = 20
  79. @('Maintenance','Technology') | ForEach-Object {[void] $request.Items.Add($_)}
  80. $request.location                = New-Object System.Drawing.Point(122,113)
  81. $request.Font                    = 'Microsoft Sans Serif,10'
  82.  
  83. $btn1                            = New-Object system.Windows.Forms.Button
  84. $btn1.text                       = "Send Request"
  85. $btn1.width                      = 98
  86. $btn1.height                     = 40
  87. $btn1.location                   = New-Object System.Drawing.Point(418,323)
  88. $btn1.Font                       = 'Microsoft Sans Serif,10'
  89.  
  90. $Form.controls.AddRange(@($Label1,$Label2,$Label3,$Label4,$TextBox1,$email,$subject,$description,$request,$btn1))
  91.  
  92. #region gui events {
  93. $btn1.Add_Click({ sendRequest })
  94. #endregion events }
  95.  
  96. #endregion GUI }
  97. function sendRequest()
  98. {
  99. # API Key
  100. $FDApiKey="apikey"
  101. #################################################
  102.  
  103. # Force TLS1.2 as Powershell defaults to TLS 1.0 and Freshdesk will fail connections
  104. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
  105.  
  106. # Prep
  107. $pair = "$($FDApiKey):$($FDApiKey)"
  108. $bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
  109. $base64 = [System.Convert]::ToBase64String($bytes)
  110. $basicAuthValue = "Basic $base64"
  111. $FDHeaders = @{ Authorization = $basicAuthValue }
  112. ##################################################
  113.  
  114. Invoke-WebRequest "https://clasd.freshdesk.com/api/v2/tickets/" -Headers $FDHeaders  -ContentType "application/json" -Method Post -Body " { 'description':'$description.Text','email':'$email.Text', 'subject':'$subject.Text','type':'$request.Text','priority':'1', 'status':'2' }"
  115. }
Advertisement
Add Comment
Please, Sign In to add comment