Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #5566 intune app configuration policy #5673

Open
wants to merge 6 commits into
base: Dev
Choose a base branch
from

Conversation

dannyKBjj
Copy link
Contributor

@dannyKBjj dannyKBjj commented Jan 26, 2025

Pull Request (PR) description

Have added a number of missing properties for the resource and added test/create support for 'Applications'

Unfortunately unable to fix 'update' due to what looks like an MgGraph issue. Added a verbose message to the code to warn the user..

reported here:
#5671

and here:
https://feedbackportal.microsoft.com/feedback/idea/c0940cc8-d7da-ef11-95f6-0022484d7a88

Similarly the module cannot support the 'Application Catalogue Settings' either. I can find them in Graph explorer but the related cmdlet doesn't work and cannot retrieve using invoke-mgGraph either.

Issue reported here
https://feedbackportal.microsoft.com/feedback/idea/f77feb49-11dc-ef11-95f6-0022484d7a88

and here
#5672

This Pull Request (PR) fixes the following issues

Task list

  • [x ] Added an entry to the change log under the Unreleased section of the file CHANGELOG.md.
    Entry should say what was changed and how that affects users (if applicable), and
    reference the issue being resolved (if applicable).
  • [ x] Resource parameter descriptions added/updated in the schema.mof.
  • [x ] Resource documentation added/updated in README.md.
  • [x ] Resource settings.json file contains all required permissions.
  • [x ] Examples appropriately added/updated.
  • [x ] Unit tests added/updated.
  • [x ] New/changed code adheres to DSC Community Style Guidelines.

Mostly fixes issue microsoft#5566 where the applications part of the policy was completely ignored.

Module will now detect drift when Apps are changed, and is able to correctly recreate the policy when deleted. There seems to be a problem with MgGraph that means for now, 'update' will not work. Added verbose message for now, left code that should do the 'update' commented out.

Issue has been reported here: microsoft#5671 and here https://feedbackportal.microsoft.com/feedback/idea/c0940cc8-d7da-ef11-95f6-0022484d7a88
Have added a number of missing properties for the resource and added test/create support for 'Applications'

Unfortunately unable to fix 'update' due to what looks like an MgGraph issue. Added a verbose message to the code to warn the user..

reported here:
microsoft#5671

and here:
 https://feedbackportal.microsoft.com/feedback/idea/c0940cc8-d7da-ef11-95f6-0022484d7a88

Similarly the module cannot support the 'Application Catalogue Settings' either. I can find them in Graph explorer but the related cmdlet doesn't work and cannot retrieve using invoke-mgGraph either.

Issue reported here
https://feedbackportal.microsoft.com/feedback/idea/f77feb49-11dc-ef11-95f6-0022484d7a88

and here
microsoft#5672
@dannyKBjj
Copy link
Contributor Author

Re-ran unit tests here. Work fine...

image

@dannyKBjj
Copy link
Contributor Author

This seems to be the issue:
I need to call that command to retrieve the full App information, I don't think I can fix this at my end?!

image

@salbeck-sit
Copy link
Contributor

@dannyKBjj You need to ensure that the command is defined in one of the stubs under Tests/unit/stubs. The unit-tests run by a PR won't have access to any modules

…sts/unit/stubs

Add MgBetaDeviceAppManagementTargetedManagedAppConfigurationApps to ests/unit/stubs
@dannyKBjj
Copy link
Contributor Author

That seems to have fixed it. Thanks very much for your help!

@FabienTschanz
Copy link
Contributor

I'm taking a look at the not working update method.

@FabienTschanz
Copy link
Contributor

@dannyKBjj The following code works without issues and updates the apps on the policy:

if ($null -ne $Apps)
{
    $appsArray = @()
    foreach ($app in $Apps)
    {
        if ($null -ne $app.mobileAppIdentifier.bundleID)
        {
            $mobileAppIdentifierHashtable = @{
                '@odata.type' = "#microsoft.graph.iosMobileAppIdentifier"
                bundleId      = $app.mobileAppIdentifier.bundleID
            }
        }

        if ($null -ne $app.mobileAppIdentifier.packageID)
        {
            $mobileAppIdentifierHashtable = @{
                '@odata.type' = "#microsoft.graph.androidMobileAppIdentifier"
                packageId     = $app.mobileAppIdentifier.packageId
            }
        }

        if ($null -ne $app.mobileAppIdentifier.windowsAppID)
        {
            $mobileAppIdentifierHashtable = @{
                '@odata.type' = "#microsoft.graph.windowsAppIdentifier"
                windowsAppId  = $app.mobileAppIdentifier.windowsAppId
            }
        }

        $appsArray += @{
            'mobileAppIdentifier' = $mobileAppIdentifierHashtable
        }
    }

    $appsBody = @{
        appGroupType = $AppGroupType
        apps = $appsArray
    }

    Write-Verbose -Message "Updating Apps for Intune App Configuration Policy {$DisplayName}"
    $Uri = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "/beta/deviceAppManagement/targetedManagedAppConfigurations('$($currentconfigPolicy.Id)')/targetApps"
    Invoke-MgGraphRequest -Method POST -Uri $Uri -Body $($appsBody | ConvertTo-Json -Depth 10) -Verbose
}

I switched your Update-MgBetaXXX call to the Invoke-MgGraphRequest and slightly updated your hashtable that's used for the update. I didn't touch the create stuff, I trust that it works.

Btw, please remove the IsAssigned and DeployedAppCount properties, they are readonly and would only make the drift incorrect as soon as you change the app count.

@dannyKBjj
Copy link
Contributor Author

dannyKBjj commented Jan 29, 2025

Hi, I'd tried experimenting with invoke-mggraph myself, but had no luck. I copied your code into Set-TargetResource, and tried to use it to remediate a change I made to my 'apps' for one of my policies, but it doesn't seem to be working at my end:

image

@dannyKBjj
Copy link
Contributor Author

dannyKBjj commented Jan 29, 2025

M365TenantConfig - Example.txt

I've attached an export of my test policy if you want to try yourself. The policy will create just fine using the mgBeta cmdlet. If you edit the apps and try and try and update it will fail with both my code (which I commented out) and the invoke-mgGraph method you provided... or at least it is failing at my end?!

@dannyKBjj
Copy link
Contributor Author

Should it be PATCH not POST to update an existing policy? I tried changing the code to PATCH instead, but got the same result.

@FabienTschanz
Copy link
Contributor

Should it be PATCH not POST to update an existing policy? I tried changing the code to PATCH instead, but got the same result.

It's a POST request to /targetApps. You can figure those things out if you check in the Intune portal with your browser dev tools (F12 normally) in the network tab.

image

image

@ricmestre
Copy link
Contributor

The app called Graph X-Ray it's also a good complement to the browser's dev tools

@dannyKBjj
Copy link
Contributor Author

Thanks guys, I appreciate the tips. I've been thrown in the deep-end and learning as I go along, so all help is appreciated :-D

Unfortunately the provided code just doesn't seem to be working for me?! I copy&pasted it over the if ($null -ne $Apps){} in Set-TargetResource, so don't really understand what I could have done wrong (if anything).

It is definitely working at your end?

@FabienTschanz
Copy link
Contributor

@dannyKBjj Sorry, I had a / too much. The Uri should be: $Uri = (Get-MSCloudLoginConnectionProfile -Workload MicrosoftGraph).ResourceUrl + "beta/deviceAppManagement/targetedManagedAppConfigurations('$($currentconfigPolicy.Id)')/targetApps", without the / right before beta.

@ricmestre
Copy link
Contributor

@FabienTschanz If you use Invoke-MgGraphRequest then you can start the Uri on "/beta..." without having to worry to which Graph endpoint you're connected to (so no need for calling Get-MSCloudLoginConnectionProfile), this way it just works for any environment out of the box as long as the resource is available for that type of cloud.

@FabienTschanz
Copy link
Contributor

@ricmestre Yeah that was my issue, I copy-pasted it from my test without Get-MsCloudLoginConnectionProfile and left the /beta, then added the full call to make it work in all clouds. It worked when I didn't prefix it with the full url. I added it because all Invoke-MgGraphRequest calls use the full prefix.

@ricmestre
Copy link
Contributor

ricmestre commented Jan 29, 2025

This was a problem in the past and I think you actually fixed them all, or at least most of them, where the calls had graph.microsoft.com hardcoded, but to be honest Get-MsCloudLoginConnectionProfile is not even needed, but as long as it works then it shouldn't matter and it's only a preference.

image

@dannyKBjj
Copy link
Contributor Author

Hi guys, I'm sure I'm being stupid, but I experimented a fair bit with Invoke-MgGraph myself and couldn't get it to work. I also can't get the code you kindly provided to work either... I've tried everything I can think of at this point.

@FabienTschanz
Copy link
Contributor

Please push the latest changes how you have them implemented in your resource, best with a descriptive visible error what's not working. Then I can take a look.

@dannyKBjj
Copy link
Contributor Author

Oh, I so now it is working!!! I guess I was being stupid. No idea what I was doing wrong before, but hey-ho.

I've pushed the changes.

@FabienTschanz
Copy link
Contributor

Looks good so far. Some minor formatting with a space between if and the brackets could be added and the commented lines removed, but otherwise, it's ok.

@dannyKBjj
Copy link
Contributor Author

Thanks Fabien, do you want me to make those changes, or are we letting it slide :-)

@FabienTschanz
Copy link
Contributor

Personally I'd like to have those changes in, but they are not required. Feel free to update it though to make it look even cleaner 😄

@dannyKBjj
Copy link
Contributor Author

Done

@FabienTschanz
Copy link
Contributor

LGTM 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IntuneAppConfigurationPolicy doesn't actually handle Any app settings
4 participants