Grab a copy of Workday Powershell API here at GitHub and place it in your “Program Files\WindowsPowerShell\Modules” folder.
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 |
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear(); Clear-Host function WriteXmlToScreen ([xml]$xml) { $StringWriter = New-Object System.IO.StringWriter; $XmlWriter = New-Object System.Xml.XmlTextWriter $StringWriter; $XmlWriter.Formatting = "indented"; $xml.WriteTo($XmlWriter); $XmlWriter.Flush(); $StringWriter.Flush(); Write-Output $StringWriter.ToString(); } function Get-XPath($n) { if ( $n.GetType().Name -ne 'XmlDocument' ) { "{0}/{1}" -f (Get-XPath $n.ParentNode), $n.Name } } $scriptpath = $MyInvocation.MyCommand.Path $dir = Split-Path $scriptpath Push-Location $dir $user = 'ISU_INT001_Provisioning' $SecretPassword = 'Pazzsw0rdGoezHere' $pair = "$($user):$($SecretPassword)" $where = 'https://services1.myworkday.com/ccx/service/customreport1/[YOUR TENANT]/ISU_INT001_Provisioning/RPT_INT001_Provisioning_Active_Workers_Data_Outbound?format=simplexml' $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) $basicAuthValue = "Basic $encodedCreds" $Headers = @{ Authorization = $basicAuthValue } [xml]$myxml = Invoke-WebRequest -Uri $where -Headers $Headers WriteXmlToScreen $myxml [string]$CreatePipedFile = "" [string]$ModifyPipedFile = "" #$nodes = $myxml.SelectNodes('//*') $nodes = $myxml.SelectNodes('//*') foreach ($node in $nodes) { #if ($node.Name -ne "wd:Report_Data" -AND $node.name -ne "wd:Report_Entry") if ($node.Name -ne "wd:Report_Data") { if ($node.name -eq "wd:Report_Entry") { <# Write-Host "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=" Write-Host "Name: " $node.Name Write-Host "Worker:" $node.Worker Write-Host "Worker_Type:" $node.Worker_Type switch($node.Worker_Type.ToLower()) { "yes" { $_ = "y" } "employee" {$Worker_Type = "EMP"} "contingent worker" { $Worker_Type = "CONT" } default { "You entered No." } } Write-Host "Emp_ID:" $node.Emp_ID Write-Host "Dep-Cd:" $node.Dep_Cd Write-Host "Dep_Name:" $node.Dep_Name Write-Host "Position_ID:" $node.Position_ID Write-Host "Position_Title:" $node.Position_Title Write-Host "L_Name:" $node.L_Name Write-Host "M_Name:" $node.M_Name Write-Host "F_Name:" $node.F_Name Write-Host "Entity:" $node.Entity Write-Host "Manager_ID:" $node.Manager_ID Write-Host "Director_ID:" $node.Director_ID Write-Host "Perf_Name:" $node.Pref_Name Write-Host "Leaving:" $node.LV_St_dt Write-Host "Return:" $node.Est_Ret_frm_leave Write-Host "Active:" $node.Active Write-Host "SSN: ***-**-****" Write-Host "Hire_Date:" $node.Hire_Date Write-Host "WorkEmail:" $node.WorkEmail Write-Host "`n" #> #Fix Date without '-' #Add leave dates to be added, fix 'AC' value #FT10 FT08 etc etc #Append hire date to end [datetime]$HireDate = $node.Hire_Date [datetime]$HireCompDate = $node.Hir_Comp_Dttm if (($HireDate -gt (Get-Date) -and $HireDate -lt (Get-Date).AddDays(14)) -or ($HireCompDate -lt (Get-Date).AddDays(1) -and $HireCompDate -gt (Get-Date).AddDays(-14))) #Testing for Newhire / Create { if ([string]::IsNullOrEmpty($node.WorkEmail)) { $PipedFile += "BLANK!" } $CreatePipedFile += "!CREATE_USER|" + $node.Emp_ID + "|" + $node.Dep_Cd + "|" + $node.Position_ID + "|" + $node.F_Name + "|" + $node.M_Name + "|" + $node.L_Name + "|" + $node.Entity + "|" + $node.Director_ID + "|" + $node.Dep_Name + "|" + $node.Position_title + "|" + ($node.Hire_Date -replace '-','') + "|" + ($node.SSN -replace '-','') + "|" + $node.Emp_Type + "|" + $node.WorkEmail + "|" + $node.Worker_Type +"`r`n" #$Worker_Type } ElseIf ($HireDate -gt (Get-Date).AddDays(14)) { Write-Host "User is in the future!" $node.Emp_ID " - " $HireDate } else { if ([string]::IsNullOrEmpty($node.WorkEmail)) { $PipedFile += "BLANK!" } $ModifyPipedFile += "!MODIFY_USER|" + $node.Emp_ID + "|" + $node.Dep_Cd + "|" + $node.Dep_Name + "|" + $node.Position_ID + "|" + $node.Position_title + "|" + $node.L_Name + "|" + $node.M_Name + "|" + $node.F_Name + "|" + $node.Entity + "|" + $node.Director_ID + "|" + $node.Pref_Name + "|" + ($node.LV_St_dt -replace '-','') +"|" + ($node.Est_Ret_frm_leave -replace '-','') + "|AC|" + ($node.SSN -replace '-','') + "|" + ($node.Hire_Date -replace '-','') + "|" + $node.Emp_Type + "|" + $node.WorkEmail + "|" + $node.Worker_Type +"`r`n" } #" =-=-=-=-= " $node.InnerText " | " } #Get-XPath($node) #$sid = $node.attributes['wd:Worker'].value #$dispName = $node.attributes['wd:Emp_ID'].value #$obj = new-object psobject -prop @{SID=$sid;DISPNAME=$dispName} #$objs += $obj } } #$objs Pop-Location Write-Host $CreatePipedFile Write-Host $ModifyPipedFile $CreatePipedFile | Set-Content 'C:\RecentHires.txt' $ModifyPipedFile | Set-Content 'C:\BeenHereAwhile.txt' |