forked from treestryder/powershell_module_workdayapi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUpdate-WorkdayWorkerEmail.ps1
More file actions
127 lines (110 loc) · 4.54 KB
/
Update-WorkdayWorkerEmail.ps1
File metadata and controls
127 lines (110 loc) · 4.54 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
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
function Update-WorkdayWorkerEmail {
<#
.SYNOPSIS
Updates a Worker's email in Workday, only if it is different.
.DESCRIPTION
Updates a Worker's email in Workday, only if it is different.
Change requests are always recorded in Workday's audit log even when
the email is the same. Unlike Set-WorkdayWorkerEmail, this cmdlet
first checks the current email before requesting a change.
.PARAMETER WorkerId
The Worker's Id at Workday.
.PARAMETER WorkerType
The type of ID that the WorkerId represents. Valid values
are 'WID', 'Contingent_Worker_ID' and 'Employee_ID'.
.PARAMETER Email
Sets the Workday primary, public, Work email for a Worker. This cmdlet does not
currently support other email types. Also excepts the alias EmailAddress.
.PARAMETER Human_ResourcesUri
Human_Resources Endpoint Uri for the request. If not provided, the value
stored with Set-WorkdayEndpoint -Endpoint Human_Resources is used.
.PARAMETER Username
Username used to authenticate with Workday. If empty, the value stored
using Set-WorkdayCredential will be used.
.PARAMETER Password
Password used to authenticate with Workday. If empty, the value stored
using Set-WorkdayCredential will be used.
.EXAMPLE
Update-WorkdayWorkerEmail -WorkerId 123 -Email test@example.com
.NOTES
The Set-WorkdayWorkerEmail switch -Append is not supported, as the -Secondary
switch assumes there is only one non-primary email address. At some point
it may be nessesary to implement a means to update a specific email WID.
#>
[CmdletBinding(DefaultParametersetName='Search')]
param (
[Parameter(Mandatory = $true,
ParameterSetName="Search",
Position=0)]
[ValidatePattern ('^[a-fA-F0-9\-]{1,32}$')]
[string]$WorkerId,
[Parameter(ParameterSetName="Search")]
[ValidateSet('WID', 'Contingent_Worker_ID', 'Employee_ID')]
[string]$WorkerType = 'Employee_ID',
[Parameter(ParameterSetName="Search")]
[string]$Human_ResourcesUri,
[Parameter(ParameterSetName="Search")]
[string]$Username,
[Parameter(ParameterSetName="Search")]
[string]$Password,
[Parameter(Mandatory = $true,
ParameterSetName="NoSearch")]
[xml]$WorkerXml,
[Parameter(Mandatory = $true)]
[Alias('EmailAddress')]
[string]$Email,
[ValidateSet('HOME','WORK')]
[string]$UsageType = 'WORK',
[switch]$Private,
[switch]$Secondary
)
if ([string]::IsNullOrWhiteSpace($Human_ResourcesUri)) { $Human_ResourcesUri = $WorkdayConfiguration.Endpoints['Human_Resources'] }
if ($PsCmdlet.ParameterSetName -eq 'NoSearch') {
$current = Get-WorkdayWorkerEmail -WorkerXml $WorkerXml
$WorkerType = 'WID'
$workerReference = $WorkerXml.GetElementsByTagName('wd:Worker_Reference') | Select-Object -First 1
$WorkerId = $workerReference.ID | Where-Object {$_.type -eq 'WID'} | Select-Object -ExpandProperty InnerText
} else {
$current = Get-WorkdayWorkerEmail -WorkerId $WorkerId -WorkerType $WorkerType -Human_ResourcesUri:$Human_ResourcesUri -Username:$Username -Password:$Password
}
$currentEmail = $current |
Where-Object {
$_.UsageType -eq $UsageType -and
(-not $_.Primary) -eq $Secondary
} | Select-Object -First 1
$msg = "{0} Current [$($currentEmail.Email)] Proposed [$Email]"
$output = [pscustomobject][ordered]@{
WorkerId = $WorkerId
WorkerType = $WorkerType
Email = $Email
UsageType = $UsageType
Primary = -not $Secondary
Public = -not $Private
Success = $false
Message = $msg -f 'Failed'
}
if (
$currentEmail -ne $null -and
$currentEmail.Email -eq $Email -and
$currentEmail.UsageType -eq $UsageType -and
(-not $currentEmail.Primary) -eq $Secondary -and
(-not $currentEmail.Public) -eq $Private
) {
$output.Message = $msg -f 'Matched'
$output.Success = $true
} else {
$o = Set-WorkdayWorkerEmail -WorkerId $WorkerId -WorkerType $WorkerType -Email $Email -UsageType:$UsageType -Private:$Private -Secondary:$Secondary -Human_ResourcesUri:$Human_ResourcesUri -Username:$Username -Password:$Password
if ($o -ne $null) {
if ($o.Success) {
$output.Success = $true
$output.Message = $msg -f 'Changed'
}
else {
$output.Success = $false
$output.Message = $o.Message
}
}
}
Write-Verbose $output.Message
Write-Output $output
}