-
Notifications
You must be signed in to change notification settings - Fork 0
/
create.ps1
89 lines (77 loc) · 2.73 KB
/
create.ps1
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
#region Initialize default properties
$config = ConvertFrom-Json $configuration
$p = $person | ConvertFrom-Json
$pp = $previousPerson | ConvertFrom-Json
$pd = $personDifferences | ConvertFrom-Json
$m = $manager | ConvertFrom-Json
$success = $False;
$auditLogs = [System.Collections.Generic.List[PSCustomObject]]::new()
#endregion Initialize default properties
#region Change mapping here
$onboardDate = Get-Date -Format "yyyy-MM-dd";
$domain = "t4edev.local";
$account = [PSCustomObject]@{
Action = "new"
OnboardingToken = $config.token
users = [System.Collections.Generic.List[PSCustomObject]]::new()
};
$user = [PSCustomObject]@{
Domain = $domain
SAMAccountName = $p.Accounts.ActiveDirectory.SamAccountName
OnboardingDate = $onboardDate
Attributes = [System.Collections.Generic.List[PSCustomObject]]::new()
};
#Claim ID
[void]$user.Attributes.add([PSCustomObject]@{
Name = "ID"
Value = $p.ExternalID
Options = 1
}
);
#Birth date
[void]$user.Attributes.add([PSCustomObject]@{
Name = "DOB"
Value = (Get-Date -Date $p.details.birthdate).ToUniversalTime().toString("dd/MM/yyyy")
Options = 34
}
)
[void]$account.users.Add($user);
#endregion Change mapping here
#region Execute
try {
if(-Not($dryRun -eq $True)) {
$response = (Invoke-WebRequest -Uri "$($config.ssrpmServer)/onboarding/import" -Method POST -ContentType "application/json" -Body ($account | ConvertTo-Json -Depth 10) -UseBasicParsing | ConvertFrom-Json).Success
}
else
{
$response = $true;
}
if($response -eq $true)
{
$success = $True;
$auditLogs.Add([PSCustomObject]@{
Action = "CreateAccount"
Message = "Enrolled in SSRPM onboarding for person [$($user.SAMAccountName)]";
IsError = $false;
});
}
}
catch
{
$auditLogs.Add([PSCustomObject]@{
Action = "CreateAccount"
Message = "Failed to Enroll SSRPM Onboarding: $($_)"
IsError = $True
});
Write-Error "$($_) : General error"
}
#endregion Execute
#region build up result
$result = [PSCustomObject]@{
Success= $success
AccountReference= $user.SAMAccountName
AuditLogs= $auditLogs
Account = $account
};
Write-Output $result | ConvertTo-Json -Depth 10
#endregion build up result