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

Add-IntuneWin32App error due to bug in New-IntuneWin32AppBody.ps1 #68

Open averhaegen opened 1 year ago

averhaegen commented 1 year ago

Hi,

Since the update to IntuneWin32App 1.4.0, I got this error when creating a new app (Add-IntuneWin32App). Error: "An error occurred while creating the Win32 application. Error message: Cannot index into a null array."

I debugged this problem and could trace the issue to the updated New-IntuneWin32AppBody command. In my case, I'm not using the RequirementRule parameter, and your new IF conditions are causing this error. I could fix this issue on my end by changing those statements (line 318-330 and line 377-389) from

# Add requirement rule items dynamically
if ($RequirementRule["minimumFreeDiskSpaceInMB"]) {
    $Win32AppBody.Add("minimumFreeDiskSpaceInMB", $RequirementRule["minimumFreeDiskSpaceInMB"])
}
if ($RequirementRule["minimumMemoryInMB"]) {
    $Win32AppBody.Add("minimumMemoryInMB", $RequirementRule["minimumMemoryInMB"])
}
if ($RequirementRule["minimumNumberOfProcessors"]) {
    $Win32AppBody.Add("minimumNumberOfProcessors", $RequirementRule["minimumNumberOfProcessors"])
}
if ($RequirementRule["minimumCpuSpeedInMHz"]) {
    $Win32AppBody.Add("minimumCpuSpeedInMHz", $RequirementRule["minimumCpuSpeedInMHz"])
}

to

# Add requirement rule items dynamically
if ($PSBoundParameters["RequirementRule"] -and $RequirementRule["minimumFreeDiskSpaceInMB"]) {
    $Win32AppBody.Add("minimumFreeDiskSpaceInMB", $RequirementRule["minimumFreeDiskSpaceInMB"])
}
if ($PSBoundParameters["RequirementRule"] -and $RequirementRule["minimumMemoryInMB"]) {
    $Win32AppBody.Add("minimumMemoryInMB", $RequirementRule["minimumMemoryInMB"])
}
if ($PSBoundParameters["RequirementRule"] -and $RequirementRule["minimumNumberOfProcessors"]) {
    $Win32AppBody.Add("minimumNumberOfProcessors", $RequirementRule["minimumNumberOfProcessors"])
}
if ($PSBoundParameters["RequirementRule"] -and $RequirementRule["minimumCpuSpeedInMHz"]) {
    $Win32AppBody.Add("minimumCpuSpeedInMHz", $RequirementRule["minimumCpuSpeedInMHz"])
}

So perhaps you can update this in the main code repo?

Thanks!

NickolajA commented 1 year ago

Good catch, all of my test always includes a requirement rule actually when looking at it. Thank you for reporting it! However I'd recommend you use a requirement rule so that you define the minimum windows release and architecture yourself.

NickolajA commented 1 year ago

Adding this in 1.4.1 to handle this behavior.