MSEndpointMgr / IntuneWin32App

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

Remove-IntuneWin32AppSupersedence - Relationships needs to be a array #144

Closed i5513 closed 7 months ago

i5513 commented 7 months ago

When no dependencies are found in a Win32App, I think we need to change $win32AppRelationshipsTable from:

{
    "relationships":  null
}

to

{
    "relationships":  []
}

Without the change I get:

ADVERTENCIA: An error occurred while removing supersedence configuration for Win32 app: 375fcc3b-eee8-44f3-8956-8b8d489151c0. Error message: BadRequest: { "Message": "Invalid action parameter: 'relationships'. - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: b8232255-78e2-4c1a-af96-83a811c575ec - Url: https://fef.msub06.manage.microsoft.com/AppLifecycle_2402/StatelessAppMetadataFEService/deviceAppManagement/mobileApps('375fcc3b-eee8-44f3-8956-8b8d489151c0')/microsoft.management.services.api.updateRelations hips?api-version=5023-11-15", "RetryAfter": null, "ErrorSourceService": "", "HttpHeaders": "{}"

I did not check, but may be we can do the same change with Remove-IntuneWin32AppDependency

i5513 commented 7 months ago

This was fixed in 1.4.4 versión. Closing the issue

What is the difference between

@($a)

And

if($a) { @($a) } else {@()}

?

Thank you!

NickolajA commented 7 months ago

Actually, it's not really fixed as simply outputting the @() in a statement would generate the "null" output, hence I need to update this to something similar as:

$Win32AppRelationshipsTable = [ordered]@{
    "relationships" = if ($Dependencies1) { @($Dependencies1) } else { , @() }
}

I will be adding that shortly.

i5513 commented 7 months ago

Actually, it's not really fixed as simply outputting the @() in a statement would generate the "null" output, hence I need to update this to something similar as:

$Win32AppRelationshipsTable = [ordered]@{
    "relationships" = if ($Dependencies1) { @($Dependencies1) } else { , @() }
}

I will be adding that shortly.

Actually (with powershell 5.1), @() works as proposed in our commits (And ", @()" generate a different, not wanted output):

PS C:\> $a = [ordered]@{ a = @() }
PS C:\> $a | ConvertTo-Json
{
    "a":  [

          ]
}
PS C:\> $a = [ordered]@{ a = ,@() }
PS C:\> $a | ConvertTo-Json
{
    "a":  [
              [

              ]
          ]
}

Maybe with powershell 7 change it ?

Thank you

i5513 commented 7 months ago

Sorry for reopening, it is not necessary, of course, closing

i5513 commented 7 months ago

Actually, it's not really fixed as simply outputting the @() in a statement would generate the "null" output, hence I need to update this to something similar as:

$Win32AppRelationshipsTable = [ordered]@{
    "relationships" = if ($Dependencies1) { @($Dependencies1) } else { , @() }
}

I will be adding that shortly.

Actually (with powershell 5.1), @() works as proposed in our commits (And ", @()" generate a different, not wanted output):

PS C:\> $a = [ordered]@{ a = @() }
PS C:\> $a | ConvertTo-Json
{
    "a":  [

          ]
}
PS C:\> $a = [ordered]@{ a = ,@() }
PS C:\> $a | ConvertTo-Json
{
    "a":  [
              [

              ]
          ]
}

Maybe with powershell 7 change it ?

Thank you

Well my commit was bad ... it should maintain the if

I tested :

# $b is not defined (or $null)
$a = @($b) ; $a | convertto-json
$a = @() ; $a | convertto-json

And like you comment, first case will output "null", the second is the correct in this case So

if ($Dependencies) { @($Dependencies) } else { @() }

is the solution