Skip to content

Update contact in Easit GO with data from Active Directory

Scenario

In this scenario we would like to update any contact on demand when a contact triggers an item event.

Code

    [CmdletBinding()]
    param (
        [Parameter(Mandatory,Position=0)]
        [string]$StringInput
    )
    begin {
        Import-Module -Name 'Easit.ProcessRunner.GlobalFunctions','Easit.GO.Webservice'
        Write-CustomLog -Message "Starting script"
    }
    process {
        try {
            $decodedStringInput = Read-StringAsUTF8 -InputString $StringInput
            $exportObject = $decodedStringInput | ConvertFrom-Json
            $easitObject = $exportObject.itemToImport[0]
        } catch {
            Write-CustomLog -InputObject $_ -Level ERROR
            return
        }
        try {
            $easitObject.property.GetEnumerator() | ForEach-Object {
                $easitObject | Add-Member -MemberType NoteProperty -Name $_.name -Value $_.content
            }
        } catch {
            Write-CustomLog -InputObject $_ -Level ERROR
            return
        }
        if ([string]::IsNullOrEmpty($easitObject.username)) {
            Write-CustomLog -Message "username is empty, send a request with a property named username (and a value for the property) to EPR" -Level ERROR
            return
        }
        $sendToEasitParams = @{
            Url = 'https://go.easit.com'
            Apikey = 'myApikey'
            ImportHandlerIdentifier = 'updateContact'
        }
        try {
            Get-ADUser -Identity $easitObject.username | Send-ToEasitGO @sendToEasitParams
        } catch {
            Write-CustomLog -InputObject $_ -Level ERROR
            return
        }
    }
    end {
        Write-CustomLog -Message "Script complete"
    }