MSEndpointMgr / IntuneWin32App

Provides a set of functions to manage all aspects of Win32 apps in Microsoft Intune.
MIT License
345 stars 88 forks source link

Cannot add an app with a New-IntuneWin32AppRequirementRuleRegistry. error #40

Closed hotzenwalder closed 2 years ago

hotzenwalder commented 2 years ago

I'm trying to add an win32app with a requirement for a registry string comparison, but no matter what I try it always gives me the below error

WARNING: Request to https://graph.microsoft.com/Beta/deviceAppManagement/mobileApps failed with HTTP Status BadRequest and description: Bad Request WARNING: Failed to create Win32 app using constructed body. Passing converted body as JSON to output.

When I use another detection method, like a Powershell script it works. The error is somewhere in my $detectionrule. I've checked the module New-IntuneWin32AppDetectionRuleRegistry to see what the command should look like, but if always fails, even when I use another type like Existence

My detectionrule is

$DetectionRule = New-IntuneWin32AppRequirementRuleRegistry -StringComparison -StringComparisonOperator equal -KeyPath $RegKeypath -ValueName $RegKeyValue -StringComparisonValue $Version

This transalates to

Schermafbeelding 2022-04-27 203251

My code to add the win32app

Add-IntuneWin32App -FilePath $IntuneWinFile -DisplayName $DisplayName -Description $Description -Publisher $Publisher -InstallExperience $InstallExperience -RestartBehavior $RestartBehavior -DetectionRule $DetectionRule -InstallCommandLine $InstallCommandLine -UninstallCommandLine $UninstallCommandLine -Icon $Icon -Verbose

With the below detectionrule it works, so all the other parameters in the command are fine.

Schermafbeelding 2022-04-27 203538

It just bombs out whenever I switch to a New-IntuneWin32AppRequirementRuleRegistry.

Schermafbeelding 2022-04-27 203420

Tried almost everything, so no idea what I am doing wrong here

NickolajA commented 2 years ago

You should use the following function for detection rules:

New-IntuneWin32AppDetectionRuleRegistry

Since it will create the required odata.type object: #microsoft.graph.win32LobAppRegistryDetection

Requirement rules are different, and the function you're using created a '#microsoft.graph.win32LobAppRegistryRequirement' odata.type object.