Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Microsoft Intune Cookbook

You're reading from   Microsoft Intune Cookbook Over 75 recipes for configuring, managing, and automating your identities, apps, and endpoint devices

Arrow left icon
Product type Paperback
Published in Jan 2024
Publisher Packt
ISBN-13 9781805126546
Length 574 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrew Taylor Andrew Taylor
Author Profile Icon Andrew Taylor
Andrew Taylor
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Chapter 1: Getting Started with Microsoft Intune FREE CHAPTER 2. Chapter 2: Configuring Your New Tenant for Windows Devices 3. Chapter 3: Securing Your Windows Devices with Security Policies 4. Chapter 4: Setting Up Enrollment and Updates for Windows 5. Chapter 5: Android Device Management 6. Chapter 6: iOS Device Management 7. Chapter 7: macOS Device Management 8. Chapter 8: Setting Up Your Compliance Policies 9. Chapter 9: Monitoring Your New Environment 10. Chapter 10: Looking at Reporting 11. Chapter 11: Packaging Your Windows Applications 12. Chapter 12: PowerShell Scripting across Intune 13. Chapter 13: Tenant Administration 14. Chapter 14: Looking at Intune Suite 15. Index 16. Other Books You May Enjoy

Configuring Entra ID MDM/MAM scopes

The last thing we must do before we move on to Intune is allow our users to enroll devices into Mobile Device Management (MDM) and, if required, Mobile Application Management (MAM).

MDM is for enrolling your corporate-owned devices into Intune, while MAM is for your bring-your-own devices (BYODs). MAM uses Windows Information Protection (WIP), which is only supported on Android and iOS, but we can block personal Windows devices within Intune so that we can still set this to everyone and let Intune handle the rest.

How to do it…

Follow these steps to configure your Entra ID MDM and MAM scopes:

  1. Within Microsoft Entra ID, expand Settings and click on Mobility.
  2. Within the Mobility portal, click Microsoft Intune:
Figure 1.12 – The Mobility (MDM and MAM) screen

Figure 1.12 – The Mobility (MDM and MAM) screen

  1. For this environment, set them both to All. Note you can restrict by groups – for example, only allowing users with an Intune license based on a dynamic group, or block users from enrolling completely. Leave the default URLs as is and then click Save.

With that, we have configured our Microsoft Entra environment for device enrollment.

Automating it

This is a tricky one to automate. Not only does it use the IAM API that we used for ESR, but the MDM application ID is also tenant-specific.

Let us build a PowerShell script to automate these settings:

  1. First, in your browser window, look in the address bar and grab the ID:
Figure 1.13 – Address bar object ID

Figure 1.13 – Address bar object ID

  1. Set the necessary variables, including this ID. A setting of 2 means enabled for all, while 0 means disabled:
    $MDMstatus = 2
    $MAMstatus = 2
    $policyid = "Policy ID grabbed from browser"
  2. Populate the JSON. As with the Entra ID device settings, we are manipulating the default values so that we can retrieve the current JSON with a GET request. In this case, we are only changing two settings; everything else remains the same:
    $json = @"
    {
        "appCategory": "Mdm",
        "appData": {
            "complianceUrl": "https://portal.manage.microsoft.com/?portalAction=Compliance",
            "enrollmentUrl": "https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc",
            "mamComplianceUrl": "",
            "mamEnrollmentUrl": "https://wip.mam.manage.microsoft.com/Enroll",
            "mamTermsOfUseUrl": "",
            "termsOfUseUrl": "https://portal.manage.microsoft.com/TermsofUse.aspx"
        },
        "appDisplayName": "Microsoft Intune",
        "appId": "0000000a-0000-0000-c000-000000000000",
        "isOnPrem": false,
        "logoUrl": null,
        "mamAppliesTo": $MAMstatus,
        "mamAppliesToGroups": [],
        "mdmAppliesTo": $MDMstatus,
        "mdmAppliesToGroups": [],
        "objectId": "$policyid",
        "originalAppData": {
            "complianceUrl": "https://portal.manage.microsoft.com/?portalAction=Compliance",
            "enrollmentUrl": "https://enrollment.manage.microsoft.com/enrollmentserver/discovery.svc",
            "mamComplianceUrl": "",
            "mamEnrollmentUrl": "https://wip.mam.manage.microsoft.com/Enroll",
            "mamTermsOfUseUrl": "",
            "termsOfUseUrl": "https://portal.manage.microsoft.com/TermsofUse.aspx"
        }
    }
    "@
  3. Set the URL:
    $url = "https://main.iam.ad.ext.azure.com/api/MdmApplications
    /$policyid?mdmAppliesToChanged=true&mamAppliesToChanged=true"
  4. Authenticate against the IAM API:
    ##Create Access Token
    $clientid = "1950a258-227b-4e31-a9cf-717495945fc2"
    $response = Invoke-RestMethod -Method POST -UseBasicParsing -Uri "https://login.microsoftonline.com/$tenantId/oauth2/devicecode" -ContentType "application/x-www-form-urlencoded" -Body "resource=https%3A%2F%2Fmain.iam.ad.ext.azure.com&client_id=$clientId"
    Write-Output $response.message
    $waited = 0
    while($true){
        try{
            $authResponse = Invoke-RestMethod -uri "https://login.microsoftonline.com/$tenantId/oauth2/token" -ContentType "application/x-www-form-urlencoded" -Method POST -Body "grant_type=device_code&resource=https%3A%2F%2Fmain.iam.ad.ext.azure.com&code=$($response.device_code)&client_id=$clientId" -ErrorAction Stop
            $refreshToken = $authResponse.refresh_token
            break
        }catch{
            if($waited -gt 300){
                Write-Verbose "No valid login detected within 5 minutes"
                Throw
            }
            #try again
            Start-Sleep -s 5
            $waited += 5
        }
    }
    $response = (Invoke-RestMethod "https://login.windows.net/$tenantId/oauth2/token" -Method POST -Body "resource=74658136-14ec-4630-ad9b-26e160ff0fc6&grant_type=refresh_token&refresh_token=$refreshToken&client_id=$clientId&scope=openid" -ErrorAction Stop)
        $resourceToken = $response.access_token
  5. Create the headers:
    $Headers = @{
        "Authorization" = "Bearer " + $resourceToken
        "Content-type"  = "application/json"
        "X-Requested-With" = "XMLHttpRequest"
        "x-ms-client-request-id" = [guid]::NewGuid()
        "x-ms-correlation-id" = [guid]::NewGuid()
    }
  6. Configure the policy:
    Invoke-RestMethod -Uri $url -Headers $Headers -Method PUT -Body $json -ErrorAction Stop

We now have a script to amend the MDM and MAM enrollment scopes.

You have been reading a chapter from
Microsoft Intune Cookbook
Published in: Jan 2024
Publisher: Packt
ISBN-13: 9781805126546
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image