powershell-intune-samples icon indicating copy to clipboard operation
powershell-intune-samples copied to clipboard

Win32_Application_Add.ps1 / Upload-Win32Lob aborting

Open TheCloudCrafter opened this issue 3 years ago • 2 comments

I've been learning powershell and I'm responsible for creating packages across multiple tenants. I'm trying to leverage Upload-Win32Lob and I can't seem to get it working. Any assistance would be immensely appreciated. I'm new to automation and this would make my life loads easier.

Here is my inputs with a few paths and fluff omitted:

import-module microsoft.graph.intune
. "$workdir\Import_Win32_Application_Functions.ps1"
. "$workdir\Import_Win32_Application_Table.ps1"

Connect-MSGraph
Get-AuthToken 

$UploadAppName = "adobereader"

# Win32 Application Upload
$PackageData = $AppPackagesTable | ? {$_.name -ilike $UploadAppName}
$SourceFile = "$PackageDir\$($PackageData.SourceFile)"

Upload-Win32Lob `
    -SourceFile $SourceFile `
    -publisher $PackageData.publisher `
    -description $PackageData.description `
    -detectionRules $PackageData.detectionRules `
    -returnCodes $PackageData.returnCodes `
    -installCmdLine $PackageData.installCmdLine `
    -uninstallCmdLine $PackageData.uninstallCmdLine


PS C:\> $PackageData
returnCodes      : {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hashtable, 
                   System.Collections.Hashtable...}
description      : This free PDF reader app lets you view, comment, fill out, and sign PDF forms to help you move 
                   through your workflow quickly and efficiently.
uninstallCmdLine : "powershell.exe -executionpolicy Bypass .\uninstall.ps1"
SourceFile       : acroread.intunewin
installCmdLine   : powershell.exe -executionpolicy Bypass .\install.ps1
Name             : AdobeReader
detectionRules   : {productVersion, productCode, productVersionOperator, @odata.type}
publisher        : Adobe
displayName      : Adobe Reader DC 2020 Classic Track - 2022-06-04


PS C:\> $PackageData.returnCodes

Name                           Value                                                                              
----                           -----                                                                              
returnCode                     0                                                                                  
type                           success                                                                            
returnCode                     1707                                                                               
type                           success                                                                            
returnCode                     3010                                                                               
type                           softReboot                                                                         
returnCode                     1641                                                                               
type                           hardReboot                                                                         
returnCode                     1618                                                                               
type                           retry                                                                              


PS C:\> $PackageData.detectionRules

Name                           Value                                                                              
----                           -----                                                                              
productVersion                                                                                                    
productCode                    {23170F69-40B1-2702-1604-000001000000}                                             
productVersionOperator         notConfigured                                                                      
@odata.type                    #microsoft.graph.win32LobAppProductCodeDetection      

Here is my error:

Source file found.
Testing if SourceFile 'C:\Users\PATH\AdobeReaderClassic.intunewin' Path is valid...

Creating JSON data to pass to the service...

Creating application in Intune...

Aborting with exception: System.Management.Automation.MethodInvocationException: Exception calling "Serialize" with
 "2" argument(s): "Object Graph cannot be null.
Parameter name: graph" ---> System.ArgumentNullException: Object Graph cannot be null.
Parameter name: graph
   at System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __Bin
aryWriter serWriter, Boolean fCheck)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object g
raph, Header[] headers, Boolean fCheck)
   at CallSite.Target(Closure , CallSite , Object , Object , Object )
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exceptio
n exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

TheCloudCrafter avatar Jun 04 '22 16:06 TheCloudCrafter

Looking at the sample I realized I skipped out on the beginning. So I added that to my code and got a new (400) Bad Request error.

Test-AuthToken
$baseUrl = "https://graph.microsoft.com/beta/deviceAppManagement/"
$logRequestUris = $true;
$logHeaders = $false;
$logContent = $true;
$azureStorageUploadChunkSizeInMb = 6l;
$sleep = 30
Testing if SourceFile 'C:\PATH\acroread.intunewin' Path is valid...

Creating JSON data to pass to the service...

Creating application in Intune...
POST https://graph.microsoft.com/deviceAppManagement/mobileApps
{
    "msiInformation":  null,
    "description":  "This free PDF reader app lets you view, comment, fill out, and sign PDF forms to help you move
 through your workflow quickly and efficiently.",
    "displayName":  "Adobe Acrobat Reader 2020 MUI",
    "minimumSupportedOperatingSystem":  {
                                            "v10_1607":  true
                                        },
    "fileName":  "IntunePackage.intunewin",
    "@odata.type":  "#microsoft.graph.win32LobApp",
    "privacyInformationUrl":  null,
    "notes":  "",
    "informationUrl":  null,
    "installExperience":  {
                              "runAsAccount":  "system"
                          },
    "owner":  "",
    "installCommandLine":  "powershell.exe -executionpolicy Bypass .\\install.ps1",
    "publisher":  "Adobe",
    "runAs32bit":  false,
    "uninstallCommandLine":  "powershell.exe -executionpolicy Bypass .\\uninstall.ps1",
    "setupFilePath":  "AcroRead.msi",
    "developer":  "",
    "isFeatured":  false,
    "detectionRules":  {
                           "productVersion":  null,
                           "productCode":  "{23170F69-40B1-2702-1604-000001000000}",
                           "productVersionOperator":  "notConfigured",
                           "@odata.type":  "#microsoft.graph.win32LobAppProductCodeDetection"
                       },
    "returnCodes":  [
                        {
                            "returnCode":  0,
                            "type":  "success"
                        },
                        {
                            "returnCode":  1707,
                            "type":  "success"
                        },
                        {
                            "returnCode":  3010,
                            "type":  "softReboot"
                        },
                        {
                            "returnCode":  1641,
                            "type":  "hardReboot"
                        },
                        {
                            "returnCode":  1618,
                            "type":  "retry"
                        }
                    ]
}
POST https://graph.microsoft.com/beta/deviceAppManagement/mobileApps
The remote server returned an error: (400) Bad Request.

Aborting with exception: System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

TheCloudCrafter avatar Jun 04 '22 19:06 TheCloudCrafter

I tried another package and looking at this thread I don't understand why my output JSON always says:

    "fileName":  "IntunePackage.intunewin",

This one actually says the real intunewin.

    "fileName": "Deploy-Application.intunewin",

https://github.com/microsoftgraph/powershell-intune-samples/issues/123

My sourcefile is 'acroread.intunewin' and passes the filecheck fine. I find it odd it gets renamed...

TheCloudCrafter avatar Jun 04 '22 22:06 TheCloudCrafter