This repository has been archived by the owner on Feb 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSDP-Module.psm1
189 lines (177 loc) · 6.39 KB
/
SDP-Module.psm1
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
function Resolve-Ticket {
<#
.DESCRIPTION
Used to set Resolution content and set the ticket status.
Must have all default fields completed first i.e Group/Technician/Status
.PARAMETER ServerURL
Service Desk Plus API Key defaults to 'C:\SDP\SandboxURL.txt' or you can provide a plain text version.
.PARAMETER apikey
Service Desk Plus API Key defaults to 'C:\SDP\Sandbox.key' or you can provide a plain text version.
.PARAMETER RequestID
Request ID of the ticket to modify
.PARAMETER Resolution
The plain text resolution to add to the ticket
.PARAMETER Status
Validated set currently supports "Resolved", "Closed".
.EXAMPLE
Resolve-Ticket -Resolution "Software has been installed on users computer" -RequestID 498417 -Status Resolved
Resolve-Ticket -Resolution "Software has been installed on users computer" -RequestID 498417 -Status Resolved -Verbose *> "C:\SDP\Logs\Log.txt"
Resolve-Ticket -Resolution "Duplicate Request" -RequestID 498417 -Status Closed -ServerURL "http://Servicedesk.Plus:8080" -apikey "54C597FC-D5EF-4214-BB2E-65CA0890132C"
.NOTES
Author: Gary Smith
Date: January 22, 2019
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$Resolution,
[Parameter(Mandatory = $true)]
[Int]$RequestID,
[Parameter(Mandatory = $true)]
[ValidateSet("Resolved", "Closed")]
[string]$Status,
[Parameter(Mandatory = $False)]
[string]$ServerURL = (Get-Content 'C:\SDP\SandboxURL.txt'),
[Parameter(Mandatory = $False)]
[string]$apikey = (Get-Content 'C:\SDP\Sandbox.key')
)
begin {
}
process {
$inputData = @"
{
"request": {
"resolution": {
"content": "$Resolution"
},
"status": {
"name": "$Status"
}
}
}
"@
$URI = $ServerURL + "/api/v3/requests/$RequestID" + "?TECHNICIAN_KEY=$ApiKey&input_data=$inputdata&format=json"
Invoke-WebRequest -Method PUT -Uri $URI -UseBasicParsing -Verbose
}
end {
}
}
function Set-Group_Tech {
<#
.DESCRIPTION
Used to set the Group and the Technician.
.PARAMETER ServerURL
Service Desk Plus API Key defaults to 'C:\SDP\SandboxURL.txt' or you can provide a plain text version.
.PARAMETER apikey
Service Desk Plus API Key defaults to 'C:\SDP\Sandbox.key' or you can provide a plain text version.
.PARAMETER RequestID
Request ID of the ticket to modify
.PARAMETER Group
Enter the Group name to assign the ticket to.
.PARAMETER Technician
Enter the Technician name to assign the ticket to.
.EXAMPLE
Set-Group_Tech -RequestID 498412 -Group "Service Desk" -Technician "John Doe"
Set-Group_Tech -RequestID 498412 -Group "Service Desk" -Technician "John Doe" -Verbose *> "C:\SDP\Logs\Log.txt"
Set-Group_Tech -RequestID 498412 -Group "Service Desk" -Technician "John Doe" -ServerURL "http://Servicedesk.Plus:8080" -apikey "54C597FC-D5EF-4214-BB2E-65CA0890132C"
.NOTES
Author: Gary Smith
Date: January 22, 2019
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Int]$RequestID,
[Parameter(Mandatory = $true)]
[string]$Group,
[Parameter(Mandatory = $true)]
[string]$Technician,
[Parameter(Mandatory = $False)]
[string]$ServerURL = (Get-Content 'C:\SDP\SandboxURL.txt'),
[Parameter(Mandatory = $False)]
[string]$apikey = (Get-Content 'C:\SDP\Sandbox.key')
)
begin {
}
process {
$inputData = @"
{
"request": {
"group": {
"name": "$Group"
},
"technician": {
"name": "$Technician"
}
}
}
"@
$URI = $ServerURL + "/api/v3/requests/$RequestID/assign?TECHNICIAN_KEY=$ApiKey&input_data=$inputdata&format=json"
Invoke-WebRequest -Method PUT -Uri $URI -UseBasicParsing -Verbose
#$API_response = Invoke-WebRequest -Method PUT -Uri $URI -UseBasicParsing -Verbose
#$API_response_object = $API_response | ConvertFrom-Json
}
end {
}
}
function Add-Notes {
<#
.DESCRIPTION
Used to set add notes to tickets.
.PARAMETER ServerURL
Service Desk Plus API Key defaults to 'C:\SDP\SandboxURL.txt' or you can provide a plain text version.
.PARAMETER apikey
Service Desk Plus API Key defaults to 'C:\SDP\Sandbox.key' or you can provide a plain text version.
.PARAMETER RequestID
Request ID of the ticket to modify
.PARAMETER NoteContents
Plain text that will be added to the body of the note
.EXAMPLE
Add-Notes -RequestID 498412 -NoteContents "Automatic Script was run to add software to computer ComputerName."
Add-Notes -RequestID 498412 -NoteContents "Automatic Script was run to add software to computer ComputerName." -Verbose *> "C:\SDP\Logs\Log.txt"
Add-Notes -RequestID 498412 -NoteContents "Automatic Script was run to add software to computer ComputerName."
.NOTES
Author: Gary Smith
Date: January 22, 2019
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[Int]$RequestID,
[Parameter(Mandatory = $true)]
[string]$NoteContents,
[Parameter(Mandatory = $False)]
[string]$ServerURL = (Get-Content 'C:\SDP\SandboxURL.txt'),
[Parameter(Mandatory = $False)]
[string]$apikey = (Get-Content 'C:\SDP\Sandbox.key')
)
begin {
}
process {
$inputData = @"
<API version='1.0' >
<Operation>
<Details>
<Notes>
<Note>
<parameter>
<name>isPublic</name>
<value>true</value>
</parameter>
<parameter>
<name>notesText</name>
<value>$NoteContents</value>
</parameter>
</Note>
</Notes>
</Details>
</Operation>
</API>
"@
$postparams = @{OPERATION_NAME = 'ADD_NOTE'; TECHNICIAN_KEY = $apikey; INPUT_DATA = $inputData; FORMAT = 'XML'}
#$API_response = Invoke-WebRequest -Uri "$ServerURL/sdpapi/request/$RequestID/notes" -Method POST -Body $postparams -Verbose
Invoke-WebRequest -Uri "$ServerURL/sdpapi/request/$RequestID/notes" -Method POST -Body $postparams -Verbose
}
end {
}
}