-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate.ps1
More file actions
75 lines (61 loc) · 2.41 KB
/
update.ps1
File metadata and controls
75 lines (61 loc) · 2.41 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
#region Functions
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls10 -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
function Invoke-UltimoRestMethod ($EndpointUrl, $ApiKey, $body , $Proxy) {
try {
$requestUrl = "$($script:url)/$($EndpointUrl)?ApiKey=$ApiKey"
$responseRestMethod = Invoke-RestMethod -uri $requestUrl -Method POST -Body $body -Proxy:$proxy -UseBasicParsing -ContentType "application/json"
Write-Output $responseRestMethod
} catch {
throw $_.exception.message
}
}
#endregion Functions
#Initialize default properties
$config = ConvertFrom-Json $configuration
$p = $person | ConvertFrom-Json;
$aRef = $accountReference | ConvertFrom-Json;
$success = $False;
$auditMessage = $p.DisplayName;
$script:url = $config.Url
$ApiKey = $config.apikey
$t4eUserGroupGuidUrl = $config.t4eUserGroupGuid
$t4UpdateGuidUrl = $config.t4eUpdateGuid
#Change mapping here
$account = [PSCustomObject]@{
EmployeeId = $p.externalId # Employee Number
UserId = $aRef # UserName Ultmio (User AD)
}
if (-Not($dryRun -eq $true)) {
try {
$filter = @{
filteruserid = $account.UserId
} | ConvertTo-Json
$userResult = (Invoke-UltimoRestMethod -EndpointUrl $t4eUserGroupGuidUrl -ApiKey $ApiKey -body $filter).properties.output.collection
if ($null -eq $userResult) {
throw "No user found with userid: '$($account.UserId)'"
}
$UpdateUserRequest = @{
_AuthId = "$((Get-Date).ToString("yyyyMMddhhmmssMs"))"
_AuthEmpId = $account.EmployeeId
_AuthUserId = $account.UserId
_AuthGroupId = $userResult.GroupId
} | ConvertTo-Json
$userResult = ( Invoke-UltimoRestMethod -EndpointUrl $t4UpdateGuidUrl -ApiKey $ApiKey -body $UpdateUserRequest).properties.message
if ( $userResult -match "Geen medewerker gevonden") {
throw $userResult
}
$auditMessage = "Successfully"
$success = $true
} catch {
$auditMessage = " : $($_.Exception.Message)"
}
}
#build up result
$result = [PSCustomObject]@{
Success = $success;
AccountReference = $aRef
AuditDetails = $auditMessage;
Account = $account;
};
#send result back
Write-Output $result | ConvertTo-Json -Depth 10