@@ -13,8 +13,13 @@ function Get-WorkdayWorkerPhoto {
1313 The type of ID that the WorkerId represents. Valid values
1414 are 'WID', 'Contingent_Worker_ID' and 'Employee_ID'.
1515
16+ . PARAMETER Path
17+ Path to save the photo. If Path is to a directory, the file name from Workday will be appened.
18+ If no Path is specified, a PsCustomObject is returned containing the file name and byte array.
19+
1620. PARAMETER Passthru
1721 Outputs Invoke-WorkdayRequest object, rather than a custom Worker object.
22+ If desired, the Base 64 encoded image and file name can be aquired from the XML.
1823
1924. PARAMETER Human_ResourcesUri
2025 Human_Resources Endpoint Uri for the request. If not provided, the value
@@ -30,7 +35,12 @@ function Get-WorkdayWorkerPhoto {
3035
3136. EXAMPLE
3237
33- Get-WorkdayWorkerPhoto -WorkerId 123
38+ # Get the Binary Array of a
39+ $BinaryArray = Get-WorkdayWorkerPhoto -WorkerId 123
40+
41+ . EXAMPLE
42+ #
43+
3444
3545#>
3646
@@ -49,9 +59,11 @@ Get-WorkdayWorkerPhoto -WorkerId 123
4959 ParameterSetName = ' IndividualWorker' )]
5060 [ValidateSet (' WID' , ' Contingent_Worker_ID' , ' Employee_ID' )]
5161 [string ]$WorkerType = ' Employee_ID' ,
62+ [string ]$Path ,
63+ [switch ]$Passthru ,
5264 [string ]$Human_ResourcesUri ,
5365 [string ]$Username ,
54- [string ]$Password ,
66+ [string ]$Password ,
5567 [DateTime ]$AsOfEntryDateTime = (Get-Date )
5668 )
5769
@@ -83,12 +95,30 @@ Get-WorkdayWorkerPhoto -WorkerId 123
8395 }
8496 $response = Invoke-WorkdayRequest - Request $request - Uri $Human_ResourcesUri - Username:$Username - Password:$Password
8597
86- $o = [PSCustomObject ][ordered ]@ {
87- ID = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.ID
88- Photo = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.File
98+ if ($Passthru ) {
99+ Write-Output $response
100+ }
101+ elseif ($response.Success ) {
102+ $filename = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.Filename
103+ $base64 = $response.Xml.Get_Worker_Photos_Response.Response_Data.Worker_Photo.Worker_Photo_Data.File
104+ $bytes = [System.Convert ]::FromBase64String($base64 )
105+
106+ if ([string ]::IsNullOrEmpty($Path )) {
107+ $output = [PsCustomObject ][Ordered ]@ {
108+ Filename = $filename
109+ Bytes = $bytes
110+ }
111+ Write-Output $output
112+ }
113+ else {
114+ if (Test-Path - Path $Path - PathType Container) {
115+ $Path = Join-Path $Path $filename
116+ }
117+ $bytes | Set-Content - Path $Path - Encoding Byte
118+ }
119+ }
120+ else {
121+ throw " Error calling Get_Worker_Photos_Request: $ ( $response.Message ) "
89122 }
90-
91-
92- Write-Output $o
93123 }
94- }
124+ }
0 commit comments