Copying Intune Policies across tenants – Automatically!

I’m sure most if not all of you have a test tenant (never test in production) for new policies, features etc. What happens when you then want to push this change out to live (or even to multiple customers)? You either have to JSON the policy and run the script, use a backup and restore option, or worst case manually create the policy by hand.

Lucky for you, I have developed an update to my copy script which will now copy the policy across tenants

Updated – 27/01/2023

Version 5.0 just released with:

  • Support for automation
  • Support for Graph authentication via app registration
  • Added parameters for command line usage without GUI (and running in devops pipeline/runbook)
  • Added ability to copy using only policy name
  • Parameters for ID and Name support multiple entries comma separated

Update – 05/01/2023

Version 4.0 just released adding support for:

  • Policy Sets
  • Enrollment Configuration Policies
  • Device Categories
  • Device Filters
  • Branding Profiles
  • Admin Approvals
  • Intune Terms
  • Custom roles

Update 22/12/2022 – Version 3.2 supports Windows 365 Provisioning Policies and User Settings

Update 02/12/2022 – Version 3.1 now supports new Winget Store applications (and re-written to use Graph SDK)

Update 16/09/2022 – Version 3.0 now released with added support for Applocker policies, Imported ADMX, Conditional Access, Proactive Remediations and AAD Groups

UPDATE 28/08/2022 – Version 2.0 now released which supports multiple policy selection (Ctrl-Click) to fully migrate environments

The script can be found here

Or grab from PS Gallery:

Install-Script -Name copy-intune-policy-crosstenant

As with the previous script, when you run, it will prompt for your credentials and then list all of the configured policies in the tenant in a nice table:

Simply select the policy, click the OK button and it will prompt for credentials for the destination tenant and do it’s magic.

To avoid any naming issues, the new policy will be called “Copy of” Policyname (just in case it’s an updated policy and you want to run side by side)

I hope this is of use, as always, feel free to comment below

76 thoughts on “Copying Intune Policies across tenants – Automatically!”

  1. Hello Andrew, this is awesome! Are you planning please to create a similar script that will copy AAD groups / users and groups membership to a new tenant as well (to be able to recreate core AAD+Intune configuration in a new tenant)?

    Reply
  2. Hi Andrew,

    Love the script, been looking for something like this for quite a while.

    I see this script does not support multiple policies to be migrated at the same time. Is this by design or not yet supported?
    Also, I seem to be getting this error: is it anything to worry about?

    Transcript started, output file is C:\Users\######\AppData\Local\Temp\intune-24082022.log
    Clear-Variable : Cannot find a variable with the name ‘authResult’.
    At C:\Users\#######\copy-intune-policy-crosstenant.ps1:965 char:1
    + Clear-Variable -Name authResult -Scope Global
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (authResult:String) [Clear-Variable], ItemNotFoundException
    + FullyQualifiedErrorId : VariableNotFound,Microsoft.PowerShell.Commands.ClearVariableCommand

    Please specify your destination tenant email address: #########

    Reply
    • That’s by design currently. For whole environments I would suggest the IntuneBackupandRestore module.
      I will see if I can add a checkbox to give the option of selecting a few policies though.

      I wouldn’t worry about the error, the graph tokens can be a bit fussy so I was extra brutal in killing them off, it just means it’s already ended the graph session for the source tenant

      Reply
  3. Hi,

    After logon to destination tenant i got the following error:
    addpolicy : System.Net.WebException: The remote server returned an error: (400) Invalid command..
    At Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
    At Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
    At $dir\PowerShell\Scripts\copy-intune-policy-crosstenant.ps1:1109 char:15
    + $copypolicy = addpolicy -resource $Resource -policyid $id
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,addpolicy

    Using the AzureADPreview module instead of AzureAD.
    Any idea?

    Reply
      • Hi Andrew,

        I did try it on a clean machine after confirming it is unloaded on my one.
        But got still the same error.
        On the clean machine i first installed the AzureADPreview module.

        Reply
  4. Hi

    Tried this today from a couple device, get same issues.

    Script asks for inputs, one being email, after I enter that PowerShell want to save the script. When I save PowerShell closes.

    If I reopen saved file and try again I get same thing. The GUI does not open and it doesn’t connect to tenant

    Reply
  5. Hi

    I managed to get it to run, after a few attempts, but now get a error (400) bad request
    It ran initially and copied a number of polices, but would not copy some configuration polices over, and i still cannot get these same ones to copy across.
    It does not seem to make a difference if I select 1 of these polices or multiple, i get the same error

    the log below

    Transcript started, output file is C:\Users\Keith\AppData\Local\Temp\intune-31082022.log
    Microsoft Graph Already Installed
    AZ Ad Preview Module Already Installed

    Checking for AzureAD module…
    35cfd4a4-77b5-44b2-b4d8-16736a8ac885
    PS>TerminatingError(Invoke-RestMethod): “The remote server returned an error: (400) Bad Request.”
    PS>TerminatingError(Invoke-RestMethod): “The remote server returned an error: (400) Bad Request.”
    It’s a policy
    deviceManagement/deviceConfigurations
    The authtoken is null.
    Checking for AzureAD module…
    PS>TerminatingError(Invoke-RestMethod): “The remote server returned an error: (400) Bad Request.”
    C:\Users\Keith\Documents\Untitled1.ps1 : System.Net.WebException: The remote server returned an error: (400) Bad
    Request.
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Untitled1.ps1
    C:\Users\Keith\Documents\Untitled1.ps1 : System.Net.WebException: The remote server returned an error: (400) Bad Request.
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Untitled1.ps1

    **********************
    Windows PowerShell transcript end
    End time: 20220831144854
    **********************

    Reply
  6. After you run this command (from powershell) Install-Script -Name copy-intune-policy-crosstenant, then how do you actually run the script to bring up the GUI?

    Reply
  7. Excellent tool. Just saved me hours of work. Thank you. As someone has suggested already, a copy of security groups which follow naming convention, but also is it possible to do the same for conditional access policies (report-only)? The areas it takes time to create, but probably follow best practice or a company standard.

    Reply
      • Excellent. If you need any help testing let me know. Was also thinking a copy of endpoint security baselines and AV, firewall, EDR, ASR, etc. Basically anything that requires typing out. Happy to collaborate on this also, to lessen the load.

        Reply
        • Thank you, shall do! It should already copy baselines and other security settings, they should display towards the bottom of the list.
          Conditional access policies are next on the list, just trying to get the Authtoken to work in a different scope as CA and AAD Groups are at the user level and everything else so far has been device policy level.

          Reply
  8. Yes this looks great! Super work on it! Did a test.

    Works with PowerShell 5, but if I try PS 7 (run via terminal), i get error below. PS 5

    Checking for AzureAD module…
    Authorization Access Token is null, please re-run authentication…

    I dont see conditional access policies appear. From my demo/staging tenant. Mine are mostly report-only, but there is a couple switched on.

    Anyway, looks great. Just spotted the Type column to sort. And can see Endpoint security policies in there also.

    Dont know what you mean by proactive remediations? Like a health check comparison versus baseline security config?

    Reply
    • I’ll update my PS and give it a test and see what’s going on with that.
      For proactive remediations, it can now grab those (detection and remediation scripts included) and copy those between tenants as well

      Reply
  9. Very nice scripts Andrew, thank you!
    Unfortunatly it’s not working for most of my tenants because of MFA. Are you planing to integrate that?

    Reply
  10. I get different errors for source and destination, for example:
    “Connect-MSGraph : AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new
    location, you must use multi-factor authentication to access ‘00000003-0000-0000-c000-000000000000’.”
    or
    “connect-azureAD : Response status code does not indicate success: 400 (BadRequest).”
    The Connect-MSGraph is with the credentials from the Get-Credentials, so it’s not MFA right?

    Reply
    • That looks more like a Conditional Access policy blocking things. It might be worth looking at the Azure AD sign-in logs to see what’s catching you. Feel free to use the contact form if you want me to take a look offline

      Reply
  11. I`m trying to copy some policies but I always get this errors. Do you know what is going wrong here?

    ERROR1:
    It’s a policy
    deviceManagement/deviceConfigurations
    Exception setting “omaSettings”: “The property ‘omaSettings’ cannot be found on this object. Verify that the property exists and can be set.”
    At line:1329 char:14
    + $policy.omaSettings = $policyconvert
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
    + FullyQualifiedErrorId : ExceptionWhenSetting

    ERROR2:
    Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
    At line:1842 char:27
    + … opypolicy = Invoke-RestMethod -Uri $policyuri -Headers $authToken -Me …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

    Reply
  12. Hi Andrew,

    I was testing this script and i get the following errors:
    connect-azureAD : One or more errors occurred.: AADSTS50076: Due to a configuration change made by your administrator, or because
    you moved to a new location, you must use multi-factor authentication to access ‘00000002-0000-0000-c000-000000000000’.
    Trace ID: f895017b-daa6-49e7-9d93-744a6b583700
    Correlation ID: 0c9a057c-e20e-4bb3-b9ae-2b6e96906691
    Timestamp: 2022-09-28 12:45:02Z
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

    connect-azureAD : One or more errors occurred.
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AggregateException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

    connect-azureAD : AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you
    must use multi-factor authentication to access ‘00000002-0000-0000-c000-000000000000’.
    Trace ID: f895017b-daa6-49e7-9d93-744a6b583700
    Correlation ID: 0c9a057c-e20e-4bb3-b9ae-2b6e96906691
    Timestamp: 2022-09-28 12:45:02Z
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalClaimChallengeException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

    connect-azureAD : Response status code does not indicate success: 400 (BadRequest).
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], HttpRequestException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

    connect-azureAD : {“error”:”interaction_required”,”error_description”:”AADSTS50076: Due to a configuration change made by your
    administrator, or because you moved to a new location, you must use multi-factor authentication to access
    ‘00000002-0000-0000-c000-000000000000’.\r\nTrace ID: f895017b-daa6-49e7-9d93-744a6b583700\r\nCorrelation ID:
    0c9a057c-e20e-4bb3-b9ae-2b6e96906691\r\nTimestamp: 2022-09-28 12:45:02Z”,”error_codes”:[50076],”timestamp”:”2022-09-28 12:45:02Z”,”tr
    ace_id”:”f895017b-daa6-49e7-9d93-744a6b583700″,”correlation_id”:”0c9a057c-e20e-4bb3-b9ae-2b6e96906691″,”error_uri”:”https://login.mic
    rosoftonline.com/error?code=50076″,”suberror”:”basic_action”}: Unknown error
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

    connect-azureAD : One or more errors occurred.: AADSTS50076: Due to a configuration change made by your administrator, or because
    you moved to a new location, you must use multi-factor authentication to access ‘00000002-0000-0000-c000-000000000000’.
    Trace ID: f895017b-daa6-49e7-9d93-744a6b583700
    Correlation ID: 0c9a057c-e20e-4bb3-b9ae-2b6e96906691
    Timestamp: 2022-09-28 12:45:02Z
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1609 char:1
    + connect-azureAD -Credential $credential
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Connect-AzureAD], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.Open.Azure.AD.CommonLibrary.AadAuthenticationFailedException,Microsoft.Open.Azure.AD.CommonL
    ibrary.ConnectAzureAD

    Connect-MSGraph : AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you
    must use multi-factor authentication to access ‘00000003-0000-0000-c000-000000000000’.
    Trace ID: bb2abbd8-5988-4b60-b903-d1133b987000
    Correlation ID: 7c20492c-499c-49c3-bff9-2b02de5174cf
    Timestamp: 2022-09-28 12:45:03Z
    At C:\Scripts\copy-intune-policy-crosstenant.ps1:1611 char:1
    + Connect-MSGraph -Credential $credential -PassThru
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Connect-MSGraph], AdalClaimChallengeException
    + FullyQualifiedErrorId : Microsoft.IdentityModel.Clients.ActiveDirectory.AdalClaimChallengeException,Microsoft.Intune.PowerShel
    lGraphSDK.PowerShellCmdlets.Connect

    I think i get this because i don’t get a MFA when i login with the script.

    Charles

    Reply
  13. Newb here. Not sure what I’m doing wrong, but the 2nd prompt for destination tenant never appears.

    It returns:
    It’s a Settings Catalog
    deviceManagement/configurationPolicies
    Get-MSGraphNextPage : Not authenticated. Please use the “Connect-MSGraph” command to authenticate.
    At line:287 char:25
    + … $page = Get-MSGraphNextPage -NextLink $currentNextLink
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : AuthenticationError: (:) [Get-MSGraphNextPage], InvalidOperationException
    + FullyQualifiedErrorId : PowerShellGraphSDK_NotAuthenticated,Microsoft.Intune.PowerShellGraphSDK.PowerShellCmdlets.GetNextPage

    Reply
  14. Hi Andrew
    When irun the script , it ask credential but after that i get error:
    Authorization Access Token is null, please re-run authentication…

    Reply
  15. Hi Andrew

    Great script and great content ( Love the weekly digest email ) 🙂

    I ran into all of the above issues flagged by charles and DS McG

    Ignoring the errors i was able to move 3 policies in one go that were Device restrictions and Endpoint Protection . However if they were Admin Templates then i can only do one at a time . I am running VERSION 3.0.2

    Any ideas on why on what steps to take ?

    Thanks

    Reply
    • Hi Shaun,
      Glad you’re finding it useful. Is it a built-in admin template or an ingested ADMX you are testing with? I had to add extra steps for admin templates so I might need to move them into a different loop. I’ll do some testing

      Reply
  16. Hi Andrew

    They were built in Admin Templates.. when i select more than one it seems to copy.. but then on the destination side i only have the first template i selected

    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    0c1166d1-3375-4546-8892-d2ba61640693
    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    1227a1cc-6bd8-43ec-b1ff-c84406ee8987
    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations

    Reply
    • Just uploaded 3.0.3 which should fix it. Admin Templates are temperamental so you may see some timeout errors, but you can ignore those (I can’t find any commands to get it not to report them).
      Will look at the AAD authentication issue as well, but this should get you up and running for now.

      Reply
  17. Ok just tested and it still only seems to copy 1 template

    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    43315aaa-4ab7-4477-a49b-4588a0a112a0
    It’s a Settings Catalog
    deviceManagement/configurationPolicies
    3b84e0ba-5ea0-4547-8af7-1187ec92aece
    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    0c1166d1-3375-4546-8892-d2ba61640693
    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    1227a1cc-6bd8-43ec-b1ff-c84406ee8987
    It’s an Admin Template
    deviceManagement/groupPolicyConfigurations
    The authtoken is null.
    Checking for AzureAD module…
    Connect-AzureAD : One or more errors occurred.: AADSTS50076: Due to a configuration change made by your administrator,
    or because you moved to a new location, you must use multi-factor authentication to access

    Reply
  18. Hi Andrew

    Yes, that did work, Also the output was slightly different

    createdDateTime : 2022-09-23T22:10:54.0064878Z
    enabled : False
    configurationType : policy
    id : 61401433-531b-4b3a-9e60-d47faae8f5a8
    lastModifiedDateTime : 2022-09-23T22:10:54.0064878Z

    @odata.context : https://graph.microsoft.com/beta/$metadata#deviceManagement/groupPolicyConfigurations('7e4ad996-
    5fc7-4029-b884-9937c5802bc9′)/definitionValues/$entity
    createdDateTime : 2022-10-23T23:05:03.8404742Z
    enabled : False
    configurationType : policy
    id : 77298901-4897-4c7b-82c1-afae9b5ac2e0
    lastModifiedDateTime : 2022-10-23T23:05:03.8404742Z

    createdDateTime : 2022-09-22T10:22:38.333433Z
    enabled : False
    configurationType : policy
    id : a6ea00f9-c05b-4b53-b7e3-182b4c800814
    lastModifiedDateTime : 2022-09-22T10:22:38.333433Z

    Reply
  19. Hi Andrew

    Just some more feedback on this

    I used the PS Gallery install to copy some Endpoint security policies to another tenant, I was able to copy 3 at a time. With no errors. Not sure if this was possible before

    thanks

    Reply
  20. Hi Andrew

    Tested this out

    I seem to get a bunch of the same errors compliainign about MFA

    AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new
    location, you must use multi-factor authentication to access ‘00000003-0000-0000-c000-000000000000’.

    it goes through to list all the configurations , i can select them but only copies one

    thanks

    Reply
    • Hi Shaun, Just setup a new tenant to test this myself and it copies multiple profiles for me. Any chance you can email me (contact form will work) what’s in your policies and I’ll see if I can fully duplicate my end.

      Reply
  21. Morning,

    When running the script, I get the below error every time after connecting to graph on the source tenant.

    Welcome To Microsoft Graph!
    Get-MgIdentityConditionalAccessPolicy : You cannot perform the requested operation, required scopes are missing in the token.

    Also, this error when trying to copy a settings catalog

    Welcome To Microsoft Graph!
    Invoke-MgGraphRequest : POST https://graph.microsoft.com/beta/deviceManagement/configurationPolicies
    HTTP/1.1 400 Bad Request
    Transfer-Encoding: chunked
    Vary: Accept-Encoding
    Strict-Transport-Security: max-age=31536000
    request-id: c95830b9-89c9-4676-a5d1-1b057a5e4f30
    client-request-id: c95830b9-89c9-4676-a5d1-1b057a5e4f30
    x-ms-ags-diagnostic: {“ServerInfo”:{“DataCenter”:”UK South”,”Slice”:”E”,”Ring”:”3″,”ScaleUnit”:”003″,”RoleInstance”:”LO2PEPF00001242″}}
    Date: Tue, 29 Nov 2022 10:54:23 GMT
    Content-Encoding: gzip
    Content-Type: application/json
    {“error”:{“code”:”ModelValidationFailure”,”message”:”The annotation ‘odata.count’ was found. This annotation is either not recognized or not expected at the current position.”,”innerError”:{“message”:”The annotation ‘odata.count’ was found. This annotation is either not
    recognized or not expected at the current position.”,”date”:”2022-11-29T10:54:23″,”request-id”:”c95830b9-89c9-4676-a5d1-1b057a5e4f30″,”client-request-id”:”c95830b9-89c9-4676-a5d1-1b057a5e4f30″}}}
    At C:\Users\Simon.Todd\OneDrive – One IT Services & Solutions\Desktop\Intune-Tenant-Copy.ps1:1376 char:27
    + … opypolicy = Invoke-MgGraphRequest -Uri $policyuri -Method Post -Body …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (Method: POST, R…harset=utf-8
    }:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
    + FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.InvokeMgGraphRequest

    Any advice would be much appreciated

    Simon

    Reply
  22. Hi Andrew,

    Thank you for that, I’ve tried to run the amended version but I get the below error:

    Connect-MgGraph : AADSTS650053: The application ‘Microsoft Graph PowerShell’ asked for scope ‘Policy.ReadWrite.All’ that doesn’t exist on the resource
    ‘00000003-0000-0000-c000-000000000000’. Contact the app vendor.
    Trace ID: ed8a1fad-4578-48b4-ba3b-3ab54cba3001
    Correlation ID: 80de3779-5dfe-4ec6-bd77-f53d4f0c8a3d
    Timestamp: 2022-11-29 13:53:02Z
    At line:1144 char:1

    Thanks

    Reply
  23. Hey Andrew. Great idea. Ive been trying to run it but seem to be getting stuck in a login loop. I log in and authenticate and then it just keeps asking me to pick an account and log in again. Am i doing something wrong?

    Thanks

    Reply
  24. Hi Andrew,

    We encountered a slight issue with settings catalogs in particular. If the policy has a large number of settings configured after a certain point the settings in the policies where not copied over. After some investigation we found that it was due to paging in Microsoft graph and in particular the @odata.nextlink value storing the next ‘batch’ of settings in that policy that we needed to request and then combine with the original request. We overcome by injecting the below code on the getpolicyjson command.

    $policynextlink = $settings.”@odata.nextlink”

    while ($policynextlink -ne $null)
    {
    $nextsettings = (Invoke-MgGraphRequest -Uri $policynextlink -Method Get -OutputType PSObject).value
    $policynextlink = $nextsettings.”@odata.nextLink”
    $settings += $nextsettings
    }

    Reply

Leave a Comment