Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-AzureStorageBlobUploadFinalize, missing Content-Type header #155

Open
CatalinTRSK opened this issue Apr 16, 2024 · 13 comments
Open

Comments

@CatalinTRSK
Copy link

Hello, can you please add this headers to the Invoke-AzureStorageBlobUploadFinalize function?

 $headers = @{"Content-Type" = "text/plain; charset=UTF-8"}
 $WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -Headers $headers -ErrorAction Stop
@jyonke
Copy link

jyonke commented Apr 16, 2024

This appears to be related to PowerShell Core version 7.4.2. If I downgrade to 7.4.1, I no longer see this issue.

Screenshot 2024-04-16 111054

@LeeParWal
Copy link

Just adding a quick note - we've seen early promising signs testing this on our parallel project where we similarly didn't have the header declared on the finalize call and ran into 7.4.2 when it landed on the AZDO agents yesterday.

@lsalle
Copy link

lsalle commented Apr 23, 2024

I can confirm that IntuneWin32App.Add-IntuneWin32App fails with Powershell 7.4.2.

Console output include the messages:

"
WARNING: Failed to finalize Azure Storage blob upload. Error message: The given key 'Content-Type' was not present in the dictionary.
WARNING: Intune service request for operation 'CommitFile' failed
WARNING: Failed to create Win32 app, commit file request operation failed
"

The issue could be circumvented by using Windows Powershell 5.1.

@RutgerP
Copy link

RutgerP commented May 9, 2024

I'm also getting the error on file Invoke-AzureStorageBlobUploadChunk.ps1.
Anyone has a solution for this or should I go back to Powershell 5.1?

image
image

@jaspain
Copy link

jaspain commented May 14, 2024

I ran into this same problem today with PowerShell 7.4.2 and Micrsosft.Graph 2.19.0. \IntuneWin32App\1.4.4\Private\Invoke-AzureStorageBlobUploadFinalize.ps1 threw the warnings:

WARNING: Failed to finalize Azure Storage blob upload. Error message: The given key 'Content-Type' was not present in the dictionary.
WARNING: Intune service request for operation 'CommitFile' failed
WARNING: Failed to create Win32 app, commit file request operation failed

To fix this, starting in line 35, change:

$XML += '</BlockList>'

try {
    $WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -ErrorAction Stop
}

to

$XML += '</BlockList>'

$Headers = @{
    "content-type" = "text/plain; charset=iso-8859-1"
}
try {
    $WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Headers $Headers -Body $XML -ErrorAction Stop
}

See also Add-IntuneWin32App.ps1 'CommitFile' failed error with PowerShell 7.4.0 #128, where the same problem occurred in AzureStorageBlobUploadChunk.ps1.

@RutgerP
Copy link

RutgerP commented May 15, 2024

I ran into this same problem today with PowerShell 7.4.2 and Micrsosft.Graph 2.19.0. \IntuneWin32App\1.4.4\Private\Invoke-AzureStorageBlobUploadFinalize.ps1 threw the warnings:

WARNING: Failed to finalize Azure Storage blob upload. Error message: The given key 'Content-Type' was not present in the dictionary.
WARNING: Intune service request for operation 'CommitFile' failed
WARNING: Failed to create Win32 app, commit file request operation failed

To fix this, starting in line 35, change:

$XML += '</BlockList>'

try {
    $WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -ErrorAction Stop
}

to

$XML += '</BlockList>'

$Headers = @{
    "content-type" = "text/plain; charset=iso-8859-1"
}
try {
    $WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Headers $Headers -Body $XML -ErrorAction Stop
}

See also Add-IntuneWin32App.ps1 'CommitFile' failed error with PowerShell 7.4.0 #128, where the same problem occurred in AzureStorageBlobUploadChunk.ps1.

Thanks got it running again!

wasbeer added a commit to wasbeer/IntuneWin32App that referenced this issue May 25, 2024
@rdoloto-nps
Copy link

going to close other issue. making those changes as per thread fixed.
7.4.2 powershell

@aollivierre
Copy link

aollivierre commented Jun 13, 2024

Please update the function Invoke-AzureStorageBlobUploadFinalize to fix the issue with PS 7.4.2. FYI Handle-Error is a custom function that I built wrapping out Get-Error (VERY USEFUL in PS7)

The error message indicates that the 'Content-Type' key is not present in the dictionary when making the Invoke-RestMethod call. This suggests that the Content-Type header is required for the request but is missing.

By explicitly setting the Content-Type header to application/xml, the Invoke-RestMethod call should properly handle the request. This should resolve the KeyNotFoundException error you encountered.

You can add the Content-Type header explicitly to the Invoke-RestMethod call. Here's the modified function:

\IntuneWin32App\1.4.4\Private\Invoke-AzureStorageBlobUploadFinalize.ps1

function Invoke-AzureStorageBlobUploadFinalize {
    <#
    .SYNOPSIS
        Finalize upload of chunks of the .intunewin file into Azure Storage blob container.

    .DESCRIPTION
        Finalize upload of chunks of the .intunewin file into Azure Storage blob container.

        This is a modified function that was originally developed by Dave Falkus and is available here:
        https://github.com/microsoftgraph/powershell-intune-samples/blob/master/LOB_Application/Win32_Application_Add.ps1        

    .NOTES
        Author:      Nickolaj Andersen
        Contact:     @NickolajA
        Created:     2020-01-04
        Updated:     2020-01-04

        Version history:
        1.0.0 - (2020-01-04) Function created
    #>    
    param(
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$StorageUri,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.Object]$ChunkID
    )
    $Uri = "$($StorageUri)&comp=blocklist"
	$XML = '<?xml version="1.0" encoding="utf-8"?><BlockList>'
	foreach ($Chunk in $ChunkID) {
		$XML += "<Latest>$($Chunk)</Latest>"
	}
	$XML += '</BlockList>'

	try {
        $Headers = @{
            "Content-Type" = "application/xml"
        }
		$WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -Headers $Headers -ErrorAction Stop
	}
	catch {
		# Write-EnhancedLog -Message "Failed to finalize Azure Storage blob upload. Error message: $($_.Exception.Message)"

        Handle-Error -ErrorRecord $_
	}
}

@Soolkiki
Copy link

Soolkiki commented Jul 2, 2024

We can confirm we're have this issue on version 7.4.3 as well.
image

We don't have a good way to overload the Content-Type since we're running this in a Github Runner. Is this still an issue you're reviewing?

@k0space
Copy link

k0space commented Jul 8, 2024

Having this issue as well.
CreatingIntuneAppConfigProfFailure
Works on PowerShell 5.1, but because this is in a pipeline we cannot explicitly set the Content-Type header as suggested.

@PckgrTom
Copy link

Please update the function Invoke-AzureStorageBlobUploadFinalize to fix the issue with PS 7.4.2. FYI Handle-Error is a custom function that I built wrapping out Get-Error (VERY USEFUL in PS7)

The error message indicates that the 'Content-Type' key is not present in the dictionary when making the Invoke-RestMethod call. This suggests that the Content-Type header is required for the request but is missing.

By explicitly setting the Content-Type header to application/xml, the Invoke-RestMethod call should properly handle the request. This should resolve the KeyNotFoundException error you encountered.

You can add the Content-Type header explicitly to the Invoke-RestMethod call. Here's the modified function:

\IntuneWin32App\1.4.4\Private\Invoke-AzureStorageBlobUploadFinalize.ps1

function Invoke-AzureStorageBlobUploadFinalize {
    <#
    .SYNOPSIS
        Finalize upload of chunks of the .intunewin file into Azure Storage blob container.

    .DESCRIPTION
        Finalize upload of chunks of the .intunewin file into Azure Storage blob container.

        This is a modified function that was originally developed by Dave Falkus and is available here:
        https://github.com/microsoftgraph/powershell-intune-samples/blob/master/LOB_Application/Win32_Application_Add.ps1        

    .NOTES
        Author:      Nickolaj Andersen
        Contact:     @NickolajA
        Created:     2020-01-04
        Updated:     2020-01-04

        Version history:
        1.0.0 - (2020-01-04) Function created
    #>    
    param(
        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string]$StorageUri,

        [parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [System.Object]$ChunkID
    )
    $Uri = "$($StorageUri)&comp=blocklist"
	$XML = '<?xml version="1.0" encoding="utf-8"?><BlockList>'
	foreach ($Chunk in $ChunkID) {
		$XML += "<Latest>$($Chunk)</Latest>"
	}
	$XML += '</BlockList>'

	try {
        $Headers = @{
            "Content-Type" = "application/xml"
        }
		$WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -Headers $Headers -ErrorAction Stop
	}
	catch {
		# Write-EnhancedLog -Message "Failed to finalize Azure Storage blob upload. Error message: $($_.Exception.Message)"

        Handle-Error -ErrorRecord $_
	}
}

Thanks for this fix mate!

@SunsparcSolaris
Copy link

SunsparcSolaris commented Aug 7, 2024

I am on Powershell 7.4.4 and IntuneWin32App module version 1.4.4 yet still encountering this issue. I have made the necessary changes to the files, they appear identically to the fix examples posted earlier in this thread.

WARNING: Failed to finalize Azure Storage blob upload. Error message: The given key 'Content-Type' was not present in the dictionary.
WARNING: Intune service request for operation 'CommitFile' failed
WARNING: Failed to create Win32 app, commit file request operation failed

Invoke-AzureStorageBlobUploadFinalize.ps1, starting line 35

$XML += '</BlockList>'

	try {
        $Headers = @{
            "Content-Type" = "application/xml"
        }
		$WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -Headers $Headers -ErrorAction Stop
	}

I also tried adding -ContentType "application/xml" to the Invoke-RestMethod command in the file to no avail.

@obuolinis
Copy link

I am on Powershell 7.4.4 and IntuneWin32App module version 1.4.4 yet still encountering this issue. I have made the necessary changes to the files, they appear identically to the fix examples posted earlier in this thread.

Just tested the fix from #157 with PS 7.4.4 and can confirm it does the job.
It's just unfortunate that Nickolaj can't find time to merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests