Last active
April 10, 2019 06:06
-
-
Save darrenjrobinson/b8e04978fe8c9281557da01b3b87a8fb to your computer and use it in GitHub Desktop.
Workday Granfeldt PowerShell Management Agent Import Script for Microsoft Identity Manager. Supporting blog post located here https://blog.darrenjrobinson.com/building-a-microsoft-identity-manager-powershell-management-agent-for-workday-hr/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
$Username, | |
$Password, | |
$Credentials, | |
$OperationType, | |
[bool] $usepagedimport, | |
$pagesize | |
) | |
$DebugFilePath = "C:\PROGRA~1\MICROS~2\2010\SYNCHR~1\EXTENS~2\Workday\Debug\WDUsersImport.txt" | |
if (!(Test-Path $DebugFilePath)) { | |
$DebugFile = New-Item -Path $DebugFilePath -ItemType File | |
} | |
else { | |
$DebugFile = Get-Item -Path $DebugFilePath | |
} | |
"Starting Import as : " + $OperationType + " - " + (Get-Date) | Out-File $DebugFile -Append | |
"Paged Import : " + $usepagedimport | Out-File $DebugFile -Append | |
"PageSize : " + $pagesize | Out-File $DebugFile -Append | |
# Workday Powershell Module | |
import-module -name "WorkdayAPI" | |
# Setup WorkdayAPI Module | |
$creds = New-Object System.Management.Automation.PSCredential ($Username, $Password) | |
Set-WorkdayCredential -Credential $creds | |
Set-WorkdayEndpoint -Endpoint Human_Resources -Uri 'https://SERVICE.workday.com/ccx/service/TENANT/Human_Resources/v30.2' | |
Save-WorkdayConfiguration | |
if (!$global:tenantObjects) { | |
# *********************** IMPORT ********************************** | |
# Get Workday Users | |
$WDayRecordsBase = Get-WorkdayWorker -WorkerType WID | |
"Retrieved Base Workday Records for $($WDayRecordsBase.Count) Users" | Out-File $DebugFile -Append | |
# *************************************************************** | |
# Counter to know where we are up to processing the Import | |
# Starting at minus 1 as our first object is 0 and I'm incrementing at the start of the loop. | |
[int]$global:objectsImported = -1 | |
# An Array for the retuned objects to go into | |
$global:tenantObjects = @() | |
# Add in our first objects | |
$global:tenantObjects += $WDayRecordsBase | |
# Set last object ID | |
$global:lastsourceObjectID = "randomstringthatwillnevermatchaGUIDforthefirstiteration" | |
} | |
# ********************* Process users into the MA ******************* | |
[int]$objectpagecount = 0 | |
foreach ($global:user in $global:tenantObjects) { | |
$global:user = $global:tenantObjects[$global:objectsImported + 1] | |
if (!$global:user -or ($global:objectsImported + 1 -eq $global:tenantObjects.count)) { | |
# nothing left to process | |
$global:MoreToImport = $false | |
break | |
} | |
if ($global:user.WorkerWid) { | |
# Get Full Record | |
$userRecord = $null | |
$userRecord = Get-WorkdayWorker -WorkerType WID $global:user.WorkerWid -IncludeWork -IncludePersonal | |
if ($userRecord) { | |
$obj = @{} | |
$obj.Add("WorkerWid", $userRecord.WorkerWid) | |
$obj.Add("objectClass", "WDUser") | |
$obj.Add("BusinessTitle", $userRecord.BusinessTitle) | |
$obj.Add("FirstName", $userRecord.FirstName) | |
$obj.Add("JobProfileName", $userRecord.JobProfileName) | |
$obj.Add("LastName", $userRecord.LastName) | |
$obj.Add("Location", $userRecord.Location) | |
$obj.Add("PreferredName", $userRecord.PreferredName) | |
$obj.Add("UserId", $userRecord.UserId) | |
$obj.Add("WorkerDescriptor", $userRecord.WorkerDescriptor) | |
$obj.Add("WorkerId", $userRecord.WorkerId) | |
$obj.Add("WorkerType", $userRecord.WorkerType) | |
$obj.Add("WorkerTypeReference", $userRecord.WorkerTypeReference) | |
$obj.Add("WorkSpace", $userRecord.WorkSpace) | |
"UserObjectID: " + $userRecord.WorkerId | Out-File $DebugFile -Append | |
# Pass the User Object to the MA | |
$obj | |
$objectpagecount++ | |
$global:objectsImported++ | |
"Paged Import User count: " + $objectpagecount | Out-File $DebugFile -Append | |
"Objects Imported count: " + $global:objectsImported | Out-File $DebugFile -Append | |
"Objects Remaining count: " + ($global:tenantObjects.count - $global:objectsImported - 1) | Out-File $DebugFile -Append | |
} | |
if ($objectpagecount -eq $pagesize) { | |
$global:MoreToImport = $true | |
"More to Import: " + $objectpagecount | Out-File $DebugFile -Append | |
break | |
} | |
} | |
} | |
# *********************************************************** | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment