-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ps1
More file actions
60 lines (56 loc) · 2.65 KB
/
action.ps1
File metadata and controls
60 lines (56 loc) · 2.65 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
# TOPdesk-Task-SA-Target-TOPdesk-OperatorUnarchive
###########################################################
# Form mapping
$userId = $form.id
$userDisplayName = $form.displayName
try {
Write-Information "Executing TOPdesk action: [UnarchiveOperatorAccount] for: [$($userDisplayName)]"
Write-Verbose "Creating authorization headers"
# Create authorization headers with TOPdesk API key
$pair = "${topdeskApiUsername}:${topdeskApiSecret}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$key = "Basic $base64"
$headers = @{
"authorization" = $Key
"Accept" = "application/json"
"Partner-Solution-Id" = "TOOL001"
}
Write-Verbose "Unarchiving TOPdesk Operator for: [$($userDisplayName)]"
$splatUnarchiveUserParams = @{
Uri = "$($topdeskBaseUrl)/tas/api/operators/id/$($userId)/unarchive"
Method = "PATCH"
Verbose = $false
Headers = $headers
ContentType = "application/json; charset=utf-8"
}
$response = Invoke-RestMethod @splatUnarchiveUserParams
$auditLog = @{
Action = "EnableAccount"
System = "TOPdesk"
TargetIdentifier = [String]$response.id
TargetDisplayName = [String]$response.dynamicName
Message = "TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)] executed successfully"
IsError = $false
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Information "TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)] executed successfully"
}
catch {
$ex = $_
$auditLog = @{
Action = "EnableAccount"
System = "TOPdesk"
TargetIdentifier = ""
TargetDisplayName = [String]$userDisplayName
Message = "Could not execute TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)], error: $($ex.Exception.Message)"
IsError = $true
}
if ($($ex.Exception.GetType().FullName -eq "Microsoft.PowerShell.Commands.HttpResponseException")) {
$auditLog.Message = "Could not execute TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)]"
Write-Error "Could not execute TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)], error: $($ex.ErrorDetails)"
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Error "Could not execute TOPdesk action: [EnableOperatorAccount] for: [$($userDisplayName)], error: $($ex.Exception.Message)"
}
###########################################################