This article has 303 words.
Connecting to Active Directory
What do you need?
- the OU from which you will want to enlist users. In this article we will use “OU=My Company,DC=ad-lab-domain,DC=local”.
 - token to connect to okKoala. Log in to your okKoala admin account, go to Settings > Integration > API Token > Show.
 
Step 1: Testing the data
Prepare a Powershell script, insert and run the following code.Take into account which OU you want to retrieve users from.
$users = Get-ADUser -Filter * -SearchBase "OU=My Company,DC=ad-lab-domain,DC=local"
foreach ($user in $users) {
    $body = @{
        "email" = $user.UserPrincipalName;
        "first_name" = $user.GivenName;
        "last_name" = $user.Surname;
    }
    $body
}
In our example, we have this result:
Name                           Value
----                           -----
email                          john.smith@ad-lab-domain.local
last_name                      Smith
first_name                     John
email                          jane.doe@ad-lab-domain.local
last_name                      Doe
first_name                     Jane
email                          jan.kowalski@ad-lab-domain.local
last_name                      Kowalski
first_name                     Jan
You may have to change the parameter so that, for example, the email is not retrieved from the UPN ($user.UserPrincipalName), but from the email field ($user.EmailAddress).
Step 2: Create the connection
Modify the following script according to what you did in the previous step. In place of <TOKEN FROM KOALI> insert your admin token from okKoala.
$headers = @{
    "Authorization"= "<KOALA's TOKEN>";
}
$users = Get-ADUser -Filter * -SearchBase "OU=My Company,DC=ad-lab-domain,DC=local"
foreach ($user in $users) {
    $body = @{
        "email" = $user.UserPrincipalName;
        "first_name" = $user.GivenName;
        "last_name" = $user.Surname;
    }
    try {
        $resp = Invoke-WebRequest -Uri "https://api.okkoala.com/users" `
            -Headers $headers `
            -Method POST `
            -Body ($body|ConvertTo-Json) `
            -ContentType "application/json" `
        $resp
        If ($resp.StatusCode -gt 199 -and $resp.StatusCode -lt 300) {
            $status = "OK"
        } Else {
            $status = "Error"
        }
        Write-Host $params.email ":" $status
    } catch {
        $_.Exception
    }
}
Run the script, users will appear in the okKoala panel. There you can assign licenses.
(Optional) Step 3: Create a synchronization schedule.
You can add the prepared script to tasks on the server. Follow the Microsoft documentation: