-
Book Overview & Buying
-
Table Of Contents
Microsoft Intune Cookbook
By :
Now that our tenant has been set up, we can create our first user. This recipe will run through how to create your first user and then look at what is happening in the Graph API underneath.
Navigate to the Microsoft Entra portal at https://entra.microsoft.com/#home.
Here, you will find an overview of your tenant, including your tenant ID, which you will find yourself needing when setting up policies such as OneDrive within Intune. You cannot display it within Intune directly, so you will have to navigate back to Entra ID to find it.
Within Entra ID, click on Users, then All users; you will see the user you set up when enrolling the tenant. This user will have Global Administrator access across the whole tenant, so we will create a new user to test role assignment, license assignment, and group membership.
Follow these steps to create an additional non-admin user in your tenant. The new user screen runs across a few pages, so we will concentrate on cropped screenshots of the appropriate areas:
Figure 1.2 – Entra user details
Figure 1.3 – Entra user license details
With that, you have created your first account in your new tenant.
Now, we can learn how to automate user creation.
You will need the PowerShell ISE or VS Code running for this, as we will be setting variables to send to Microsoft Graph.
Follow these steps in a new PowerShell script to create your user with Microsoft Graph:
$displayname = "User One" $givenname = "User" $surname = "One" $usageLocation = "GB" $mailNickname = "user1" $password = "PASSWORD HERE" $domainname = "DOMAIN HERE"
$json = @"
{
"accountEnabled": true,
"displayName": "$displayname",
"givenName": "$givenname",
"mailNickname": "$mailNickname",
"passwordProfile": {
"forceChangePasswordNextSignIn": true,
"password": "$password"
},
"surname": "$surname",
"usageLocation": "$usageLocation",
"userPrincipalName": "$mailnickname@$domainname"
}
"@As you can see, the JSON is a fairly straightforward array. Watch the names of the items as they are case sensitive; as an example, accountEnabled will fail if it is listed as AccountEnabled or accountenabled. The error will be a standard malformed request, so it is always a good idea to start here with any troubleshooting.
You can also see that passwordProfile is a nested array as it has further child items.
$uri = "https://graph.microsoft.com/beta/users"
GET: This simply retrieves values from Graph to manipulate, export, and morePOST: This sends new values to Graph that do not currently exist (a new user, new policy, and so on)PATCH: This updates an existing recordPUT: This is similar to PATCH but needs a full URL, including the ID being createdDELETE: This deletes whatever you are pointing it atThis is a new account we are creating, and a PUT request is more complex than a POST request, so we will stick with POST:
Invoke-MgGraphRequest -Method POST -Uri $uri -Body $json -ContentType "application/json"
This command sends a POST request to the URL we specified earlier (in this case, users) to pass the JSON we wrote. The content type tells it to look for JSON.
Now that we have our user, we can assign a role to it.