microsoftgraph / powershell-intune-samples

This repository of PowerShell sample scripts show how to access Intune service resources. They demonstrate this by making HTTPS RESTful API requests to the Microsoft Graph API from PowerShell.
MIT License
1.37k stars 658 forks source link

Uploading Win32LoB app using Az.Storage cmdlet results in commitFileFailed #217

Open degam-gh opened 2 years ago

degam-gh commented 2 years ago

Instead of 150+ lines of code for custom upload functions from the sample script, I'm trying to use the native Powershell cmdlets provided by the Az.Storage module for uploading the .intunewin binary. The upload itself works fine, but committing the file later on fails without any further error description.

This seems to be the same behaviour noted in #47, except this time this is 100% Powershell. My code:

if ($currentFileUploadRequestState -like "azureStorageUriRequestSuccess")
{
    [System.Uri]$uriObject = $fileUploadRequestResponse.azureStorageUri
    $storageAccountName = $uriObject.DnsSafeHost.Split(".")[0]
    $sasToken = $uriObject.Query.Substring(1)
    $uploadPath = $uriObject.LocalPath.Substring(1)
    $container = $uploadPath.Split("/")[0]
    $blobPath = $uploadPath.Substring($container.Length+1,$uploadPath.Length - $container.Length-1)
    $storageContext = New-AzStorageContext -StorageAccountName $storageAccountName -SasToken $sasToken
    $blobUpload = Set-AzStorageBlobContent -File $intunePackageFile -Container $container -Context $storageContext -Blob $blobPath -Force
    Write-Host "Upload finished! Details: Name $($blobUpload.Name), ContentType $($blobUpload.ContentType), Length $($blobUpload.Length), LastModified $($blobUpload.LastModified)"
}