In the following 3 articles, we’ll see how to automate the user creation, with Azure Function, with a SharePoint Online interface and with a PowerApps application.
To start in this first article, we will see how to create our new user, with an Azure Function.
We will use the following PowerShell script for this demonstration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $password $env:Password $automationAccount = $env:AutomationAccount $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ($automationAccount, $secpasswd) $lastname = $requestBody.lastname $firstname = $requestBody.firstname $PasswordProfile = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile $PasswordProfile.Password = "A_Password" Connect-AzureAd -Credential $mycreds New-AzureADUser -AccountEnabled $true -DisplayName "$firstname $lastname" -UserPrincipalName "$firstname.$lastname@florentappointaire.cloud" -PasswordProfile $PasswordProfile -MailNickName "$firstname.$lastname" Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $firstname $lastname" |
As you can understand, you will need:
- An Azure Function
- An AutomationAccount application settings, in the Azure Function, with an account that has rights to the Azure AD to create new users
- Create a Password application settings, in the Azure Function, with the password of the previous account
- To switch your Azure Function Web App to 64-bit (in Application Settings)
- Downgrading your Azure Function from version 2 to version 1 to use PowerShell because PowerShell is not yet available in version 2:
https://docs.microsoft.com/en-us/azure/azure-functions/functions -versions
- To create a new function, named cloudyjourney in my case, with PowerShell language and with type http trigger :
- To import the Azure AD module in your function cloudyjourney :
https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/
When you’ve all of these prerequisites, go in the Integrate part of your function, and select just the POST method that will be allow to receive call via the webhook (Mode) :
You can test your function, by clicking on Run and by using the following JSON code uin the Request body part, on the right :
1 2 3 4 5 6 7 |
{ "firstname": "Test", "lastname": "Cloudyjourney" } |
Creation worked correctly :
And I can now login with my new user :
My script is working. Last point, in your function, click on Get function URL and get the URL that we will use to call our webhook in SharePoint :
In the next article, we will see how to create a list in SharePoint, to start automatically our Azure Function, through the webhook, from SharePoint.