AAD- Enable Intune MDM scope to all users using Powershell

K Roja 56 Reputation points
2022-09-20T11:32:21.687+00:00

Hello Team,

We are trying to automate intune MDM scope to all users using powershell.
Do we have any Microsoft graph api or powershell to enable below property

AAD-> Mobility -> Microsoft Intune -> Configure
242966-image.png

Microsoft Security | Intune | Configuration
Microsoft Security | Microsoft Entra | Microsoft Entra ID
{count} votes

3 answers

Sort by: Most helpful
  1. Harpreet Singh Matharoo 8,396 Reputation points Microsoft Employee Moderator
    2022-09-21T09:59:26.177+00:00

    Hello @K Roja

    I have reviewed the request and found that as of now we do not have any PowerShell command to edit Mobility (MDM and MAM) settings available in Azure Portal.

    With respect to Microsoft Graph you can try below API queries to achieve this:

    243717-image.png

    243677-image.png

    I hope this answers your question.

    ----------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. Harpreet Singh Matharoo 8,396 Reputation points Microsoft Employee Moderator
    2022-10-21T07:19:34.373+00:00

    Hello @K Roja

    Ideally, we do not recommend token generation with hardcoded UPN and Password for PowerShell scripts. However, if you wish to continue with this approach then you can try below:

    **Things to consider: **

    Output of the Script would be similar to something as shown below:

    252818-image.png

    I hope this helps and resolves your concern.


    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  3. Harpreet Singh Matharoo 8,396 Reputation points Microsoft Employee Moderator
    2022-09-26T07:33:58.553+00:00

    Hello @K Roja

    If the ask is specifically about how to automate and Connect-MgGraph then you can try using Access Token for an Application/Service principal registered on Azure AD. However, this would still not be able to get any output for MDM policies as it only support on Graph calls using a work school account.

    As stated in the documentation shared in previous comment, this Graph call for mobileDeviceManagementPolicy currently do not support Application or Non-Interactive flows,
    244702-image.png

    Additionally, I was reviewing multiple document references and found that currently Connect-MgGraph does not support "-Credential" parameter. More information can be found on following page: https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/1366

    To automate scripts, you would need following:

    • An Application Registration on Azure AD. Refer Document: Register an application with Azure AD
    • You need assign relevant Graph or other permissions on Application level. Refer Document: Add permissions to access your web API
    • Create a Secret. Refer Document: Add a client secret
       $TenantId = "Tenant ID/Domain Name here"  
       $AppClientId="Add you Application ID here"  
       $ClientSecret ="Enter Client-Secret here"  
      
       $RequestBody = @{client_id=$AppClientId;client_secret=$ClientSecret;grant_type="client_credentials";scope="https://graph.microsoft.com/.default";}  
       $OAuthResponse = Invoke-RestMethod -Method Post -Uri https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token -Body $RequestBody  
       $AccessToken = $OAuthResponse.access_token  
      
       Connect-MgGraph -AccessToken $AccessToken  
      

    I hope this answers your question.

    ----------

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.