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

Can not add a single dependency to an app #122

Open P1X3 opened 11 months ago

P1X3 commented 11 months ago

After adding IntuneWin32App I can't seem to add dependency to it. The error is clearly saying that my $Dependency should be an array, and source for Add-IntuneWin32AppDependency also states that it should be an array of single or multiple. How do I wrap a single dependency to be an array of one? @($Dependency) didn't work. Casting to array also did not work.

WARNING: An error occurred while configuring dependency for Win32 app: [REMOVED]. Error message: BadRequest: The request is malformed or incorrect. Expected array for value of property: Collection(microsoft.graph.mobileAppRelations hip)

$IntuneWin32App = Add-IntuneWin32App @Win32AppArgs

$Win32AppDependency = Get-IntuneWin32App -DisplayName "HP Universal Print Driver PCL6"
$Dependency = New-IntuneWin32AppDependency -ID $Win32AppDependency.id -DependencyType AutoInstall
Add-IntuneWin32AppDependency -ID $IntuneWin32App.id -Dependency $Dependency -Verbose
P1X3 commented 11 months ago

Here is same but wrapping single dependency into array, but the same error. GetType of $Dependencies does say it is Object[] with base type Array

$IntuneWin32App = Add-IntuneWin32App @Win32AppArgs
$Win32AppDependency = Get-IntuneWin32App -DisplayName "HP Universal Print Driver PCL6"
$Dependency = New-IntuneWin32AppDependency -ID $Win32AppDependency.id -DependencyType AutoInstall
$Dependencies = @($Dependency)
Add-IntuneWin32AppDependency -ID $IntuneWin32App.id -Dependency $Dependencies -Verbose

WARNING: An error occurred while configuring dependency for Win32 app: [REMOVED]. Error message: BadRequest: The request is malformed or incorrect. Expected array for value of property: Collection(microsoft.graph.mobileAppRelations hip)

AlkHacNar commented 11 months ago

maybe my workaround for supersedence can help with Add-IntuneWin32AppDependency #123 just switch supersedence with dependency, but didn't test it

P1X3 commented 11 months ago

@AlkHacNar, yes, your workaround actually resolves the problem for dependencies too. I still fail to understand how or why existing code does not produce the same result as the one suggested in your fix.

aCID-sLAM commented 11 months ago

Also happens with version 1.4.1?

Klotzzz commented 10 months ago

I have installed Version 1.4.2 and tried the patch (as suggested above) like this:

$module = Get-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1"
$module[66] = ' "relationships" = @()' 
$module[68] = 'if ($Dependencies){ @($Win32AppRelationshipsTable.relationships += $Dependency; $Win32AppRelationshipsTable.relationships += $Dependencies) } else { @($Win32AppRelationshipsTable.relationships += $Dependency) }' 

 Set-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1" $module

But it did not work / still gave me...:

WARNING: An error occurred while configuring dependency for Win32 app: xyz. Error message: BadRequest: The request is malformed or incorrect. Expected array for value of property: Collection(microsoft.graph.mobileAppRelationship)

##############

The thing i just don't understand is: The Error tries to tell me it need an array of the type microsoft.graph.mobileAppRelationship But the module creates one of the type microsoft.graph.mobileAppDependency

But the requested type microsoft.graph.mobileAppRelationship seemingly does not contain the neccesary types of information: it misses the 'dependencyType'.

So i'm quite confused.

Any Ideas on this?

AlkHacNar commented 10 months ago

I have installed Version 1.4.2 and tried the patch (as suggested above) like this:

$module = Get-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1"
$module[66] = ' "relationships" = @()' 
$module[68] = 'if ($Dependencies){ @($Win32AppRelationshipsTable.relationships += $Dependency; $Win32AppRelationshipsTable.relationships += $Dependencies) } else { @($Win32AppRelationshipsTable.relationships += $Dependency) }' 

 Set-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1" $module

But it did not work / still gave me...:

WARNING: An error occurred while configuring dependency for Win32 app: xyz. Error message: BadRequest: The request is malformed or incorrect. Expected array for value of property: Collection(microsoft.graph.mobileAppRelationship)

##############

The thing i just don't understand is: The Error tries to tell me it need an array of the type microsoft.graph.mobileAppRelationship But the module creates one of the type microsoft.graph.mobileAppDependency

But the requested type microsoft.graph.mobileAppRelationship seemingly does not contain the neccesary types of information: it misses the 'dependencyType'.

So i'm quite confused.

Any Ideas on this?

@Klotzzz you have $Dependencies two times in the if clause, there should be dependency and $Supersedence, and its written differently. as my workaround was for supersedence, you must switch this two

$module = Get-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1"
$module[66] = '                    "relationships" = @()'
$module[67] = '                if ($Supersedence) { @($Win32AppRelationshipsTable.relationships += $Supersedence; $Win32AppRelationshipsTable.relationships += $Dependency) } else { @($Win32AppRelationshipsTable.relationships += $Dependency) }}'
Set-Content "C:\Program Files\WindowsPowerShell\Modules\IntuneWin32App\1.4.2\Public\Add-IntuneWin32AppDependency.ps1" $module

and dependency and supersedence are an object of relationship if I'm not wrong. the property relationships is the right object, but it have problems with the array objects inside, is far as I understand it atm EDIT: @Klotzzz in the Add-IntuneWin32AppDependency.ps1 the index and wording is different , so I changed it in ym scriptblock, so it should work

addovation-nioh commented 9 months ago

Here is what worked for me with module version 1.4.3 installed.

image

DennisBergemann commented 9 months ago

@P1X3 @NickolajA

Hello, the fix is much easier and the approach above would create memory issues, because of you add something to an fixed array.

Here the solution that fixes all

$Win32AppRelationshipsTable = [ordered]@{ "relationships" = @(if ($Supersedence) { @($Dependency; $Supersedence) } else { @($Dependency) })

note that the only change is to add the @() around the if ($Supersedence) { @($Dependency; $Supersedence) } else { @($Dependency) }

thats all to make it working as expected.

Greetings Dennis Bergemann

EDIT: i did not tested for now what happens when you have superscedence and Depency…

DennisBergemann commented 9 months ago

@addovation-nioh please note the memory issue in your solution because of using array +=, it will create a new array all the time.

Maybe in this case ok, but when you would have multiple, you will use more memory as you expect.

See my answer here and the easy solution or use instead of @() and += an ArrayList with add function ;-)

DennisBergemann commented 9 months ago

@P1X3

to understood what is the issue with the code from 1.43 you can look into the documentation https://learn.microsoft.com/en-us/graph/api/intune-shared-mobileapp-updaterelationships?view=graph-rest-beta

you can see there it needs an array

{
  "relationships": [
    {
      "@odata.type": "#microsoft.graph.mobileAppRelationship",
      "id": "7b4b5b14-5b14-7b4b-145b-4b7b145b4b7b",
      "targetId": "Target Id value",
      "targetDisplayName": "Target Display Name value"
    }
  ]
}

but the code from 1.43 produces this

{
  "relationships":
    {
      "@odata.type": "#microsoft.graph.mobileAppRelationship",
      "id": "7b4b5b14-5b14-7b4b-145b-4b7b145b4b7b",
      "targetId": "Target Id value",
      "targetDisplayName": "Target Display Name value"
    }  
}

this is the cause for the bad request.

What i not really understand is why @($Dependency) is not working as expected, but i copied the function out of the module and added a write out in the code to see what it sends and it sended it as no array

addovation-nioh commented 9 months ago

@P1X3 @NickolajA

Hello, the fix is much easier and the approach above would create memory issues, because of you add something to an fixed array.

Here the solution that fixes all

$Win32AppRelationshipsTable = [ordered]@{ "relationships" = @(if ($Supersedence) { @($Dependency; $Supersedence) } else { @($Dependency) })

note that the only change is to add the @() around the if ($Supersedence) { @($Dependency; $Supersedence) } else { @($Dependency) }

thats all to make it working as expected.

Greetings Dennis Bergemann

EDIT: i did not tested for now what happens when you have superscedence and Depency and i would say this is not needed as array: @($Dependency; $Supersedence) } else { @($Dependency)

Thanks this worked just fine, drop in replacement.

image

DennisBergemann commented 9 months ago

as an example this $Win32AppRelationshipsTable = [ordered]@{ "relationships" = if ($Supersedence) { @("Cat"; "Dog") } else { @("Cat") }}

produces

{
    "relationships":  "Cat"
}

but this $Win32AppRelationshipsTable = [ordered]@{ "relationships" = @(if ($Supersedence) { @("Cat"; "Dog") } else { @("Cat") })}

produces

{
    "relationships":  [
                          "Cat"
                      ]
}

and this $Win32AppRelationshipsTable = [ordered]@{ "relationships" = @(if ($true) { @("Cat"; "Dog") } else { @("Cat") })}

produces { "relationships": [ "Cat", "Dog" ] }

NickolajA commented 9 months ago

Thank you for reporting this, it's obvious that it should have been an array object created for the relationships property. I've fixed this in 1.4.4 that will be released shortly.

DennisBergemann commented 9 months ago

@NickolajA i know that it is obvious to you, everyone could see that you wanted to create the array within the if clause. It seems to be more a strange powershell behaviour that it will not return array when “if” is used as a right hand and this was what I wanted to make clearer to the ones who asked why this is an issue.

thank you for your so wonderfull work

NickolajA commented 9 months ago

For sure, that's the community spirit by spreading knowledge around! I'll look through the issue list for other pressing issues that should be in 1.4.4 and release this update shortly.

Klotzzz commented 9 months ago

Wohoo!

Thats just wunderful. So i keep quiet and lay low until then and look forward to V 1.4.4

Thanks in advance! maik

Von: Nickolaj Andersen @.> Gesendet: Samstag, 6. Januar 2024 10:50 An: MSEndpointMgr/IntuneWin32App @.> Cc: Klotzsch, Maik @.>; Mention @.> Betreff: Re: [MSEndpointMgr/IntuneWin32App] Can not add a single dependency to an app (Issue #122)

For sure, that's the community spirit by spreading knowledge around! I'll look through the issue list for other pressing issues that should be in 1.4.4 and release this update shortly.

— Reply to this email directly, view it on GitHubhttps://github.com/MSEndpointMgr/IntuneWin32App/issues/122#issuecomment-1879616583, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BDWWK3V56EYJHYQYFJQDJ7TYNEM3DAVCNFSM6AAAAAA645GVYSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZZGYYTMNJYGM. You are receiving this because you were mentioned.Message ID: @.**@.>>

Bleiben Sie mit unseren Veranstaltungen & News auf dem Laufenden! Mehr dazu unter www.gisa.de

Aufsichtsratsvorsitzender: Norbert Rotter Geschäftsführung: Heino Feige Sitz der Gesellschaft: Halle/Saale Registergericht: Amtsgericht Stendal | Handelsregister-Nr. HRB 208414 UST-ID-Nr. DE 158253683

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Empfänger sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder des Inhalts dieser Mail sind nicht gestattet. Diese Kommunikation per E-Mail ist nicht gegen den Zugriff durch Dritte geschützt. Die GISA GmbH haftet ausdrücklich nicht für den Inhalt und die Vollständigkeit von E-Mails und den gegebenenfalls daraus entstehenden Schaden. Sollte trotz der bestehenden Viren-Schutzprogramme durch diese E-Mail ein Virus in Ihr System gelangen, so haftet die GISA GmbH - soweit gesetzlich zulässig - nicht für die hieraus entstehenden Schäden. Informationen zur Verarbeitung Ihrer personenbezogenen Daten (Art. 13 DSGVO) finden Sie in unserer Datenschutzerklärung unter: https://www.gisa.de/datenschutzhinweise/

lidraro commented 8 months ago

Might be a silly question, but any idea when 1.4.4 will be released ? I tried to upgrade to 1.4.4 using install-module -name "IntuneWin32App" -requiredversion 1.4.4 , but I get no matches (I do get matches for 1.4.3). Is there another repository beside PSGallery I should add so I can download 1.4.4 ? Thanks in advance for help. I am hitting exactly this bug in my development :(.

NickolajA commented 7 months ago

Very soon!! :)

Klotzzz commented 4 months ago

@NickolajA (And everybody else) Is this issue adressed/resolved in V 1.4.4?

(I'm asking since in my case often enough the mistake is sitting on osi layer 8...)

AlkHacNar commented 4 months ago

I don't have problems with supersedence, so the dependencies should be fixed too

Klotzzz commented 4 months ago

Thanks. So i will check my methods.

Cheers!

Von: Alexej Fedorov @.> Gesendet: Mittwoch, 22. Mai 2024 13:05 An: MSEndpointMgr/IntuneWin32App @.> Cc: Klotzsch, Maik @.>; Mention @.> Betreff: Re: [MSEndpointMgr/IntuneWin32App] Can not add a single dependency to an app (Issue #122)

I don't have problems with supersedence, so the dependencies should be fixed too

— Reply to this email directly, view it on GitHubhttps://github.com/MSEndpointMgr/IntuneWin32App/issues/122#issuecomment-2124520153, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BDWWK3X2VPHPHFYJI7CUPL3ZDR3VLAVCNFSM6AAAAAA645GVYSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGUZDAMJVGM. You are receiving this because you were mentioned.Message ID: @.**@.>>

Bleiben Sie mit unseren Veranstaltungen & News auf dem Laufenden! Mehr dazu unter www.gisa.de

Aufsichtsratsvorsitzender: Norbert Rotter Geschäftsführung: Heino Feige Sitz der Gesellschaft: Halle/Saale Registergericht: Amtsgericht Stendal | Handelsregister-Nr. HRB 208414 UST-ID-Nr. DE 158253683

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Empfänger sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder des Inhalts dieser Mail sind nicht gestattet. Diese Kommunikation per E-Mail ist nicht gegen den Zugriff durch Dritte geschützt. Die GISA GmbH haftet ausdrücklich nicht für den Inhalt und die Vollständigkeit von E-Mails und den gegebenenfalls daraus entstehenden Schaden. Sollte trotz der bestehenden Viren-Schutzprogramme durch diese E-Mail ein Virus in Ihr System gelangen, so haftet die GISA GmbH - soweit gesetzlich zulässig - nicht für die hieraus entstehenden Schäden. Informationen zur Verarbeitung Ihrer personenbezogenen Daten (Art. 13 DSGVO) finden Sie in unserer Datenschutzerklärung unter: https://www.gisa.de/datenschutzhinweise/

AlkHacNar commented 4 months ago

@Klotzzz make sure it imports the 1.4.4 and not the old ones ;-) had this problem as it just came out. Installed but forgot up Reimport it

Klotzzz commented 4 months ago

Yay!

It worked 😊 Thx!

Von: Alexej Fedorov @.> Gesendet: Mittwoch, 22. Mai 2024 13:29 An: MSEndpointMgr/IntuneWin32App @.> Cc: Klotzsch, Maik @.>; Mention @.> Betreff: Re: [MSEndpointMgr/IntuneWin32App] Can not add a single dependency to an app (Issue #122)

@Klotzzzhttps://github.com/Klotzzz make sure it imports the 1.4.4 and not the old ones ;-) had this problem as it just came out. Installed but forgot up Reimport it

— Reply to this email directly, view it on GitHubhttps://github.com/MSEndpointMgr/IntuneWin32App/issues/122#issuecomment-2124562764, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BDWWK3Q6HTNRSSJ3L5ALW2LZDR6N7AVCNFSM6AAAAAA645GVYSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMRUGU3DENZWGQ. You are receiving this because you were mentioned.Message ID: @.**@.>>

Bleiben Sie mit unseren Veranstaltungen & News auf dem Laufenden! Mehr dazu unter www.gisa.de

Aufsichtsratsvorsitzender: Norbert Rotter Geschäftsführung: Heino Feige Sitz der Gesellschaft: Halle/Saale Registergericht: Amtsgericht Stendal | Handelsregister-Nr. HRB 208414 UST-ID-Nr. DE 158253683

Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Empfänger sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail oder des Inhalts dieser Mail sind nicht gestattet. Diese Kommunikation per E-Mail ist nicht gegen den Zugriff durch Dritte geschützt. Die GISA GmbH haftet ausdrücklich nicht für den Inhalt und die Vollständigkeit von E-Mails und den gegebenenfalls daraus entstehenden Schaden. Sollte trotz der bestehenden Viren-Schutzprogramme durch diese E-Mail ein Virus in Ihr System gelangen, so haftet die GISA GmbH - soweit gesetzlich zulässig - nicht für die hieraus entstehenden Schäden. Informationen zur Verarbeitung Ihrer personenbezogenen Daten (Art. 13 DSGVO) finden Sie in unserer Datenschutzerklärung unter: https://www.gisa.de/datenschutzhinweise/