Introduction
HelloID Provisioning's custom PowerShell source system is extremely flexible and powerful. With it, you can connect to virtually any source system to retrieve your organization's personnel information. The examples in this article will show how you can use the connect to leverage data from a CSV file for provisioning user accounts with HelloID.
If you haven't already done so, refer to this article for basic information regarding the PowerShell source system and its functionality. This article will provide only relevant examples and information about reading personnel and contract data from a CSV file.
Important: Any CSV file that you attempt to use as a data source should include column names in the first row of data.
Persons and Contract CSVs
The following code provides an example of how you can read personnel and contract data from CSVs on the local system, and import that data into HelloID. In practice, you should host the CSVs in a location that is accessible to all servers running the HelloID Agent.
try {
# Read personnel data from the file
$csvPersons = Import-Csv -Path "C:\HR Data\Persons.csv" -Delimiter ","
$persons = $csvPersons | Select-Object -Property *;
# Read contract data from the file
$csvContracts = Import-Csv -Path "C:\Temp\Contracts.csv" -Delimiter ";"
$allContracts = $csvContracts | Select-Object -Property *;
}
catch {
Write-Error "Something went wrong while reading one of the files";
Write-Error $_.Exception.Message;
Exit;
}
Foreach($person in $persons){
#Set two required properties ExternalID, DisplayName
$person | Add-Member -Name "ExternalId" -MemberType NoteProperty -Value $person.EmployeeID;
$person | Add-Member -Name "DisplayName" -MemberType NoteProperty -Value $person.FullName;
$contracts = @();
#Join contracts to the person change attributes in Where-Object definition to change the join#
$contracts += $allContracts | Where-Object {$_.EmployeeID -eq $person.EmployeeID};
$person | Add-Member -Name "Contracts" -MemberType NoteProperty -Value $contracts;
Write-Output $person | ConvertTo-Json -Depth 10;
}