Grab a copy of Workday Powershell API here at GitHub and place it in your “Program Files\WindowsPowerShell\Modules” folder.

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'

Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax