11param ($name )
22$Table = Get-CippTable - tablename ' apps'
3- $Filter = " PartitionKey eq 'apps' and RowKey eq '$name '"
3+ $Filter = " PartitionKey eq 'apps' and RowKey eq '$name '"
44Set-Location (Get-Item $PSScriptRoot ).Parent.FullName
55$ChocoApp = (Get-CIPPAzDataTableEntity @Table - filter $Filter ).JSON | ConvertFrom-Json
66$intuneBody = $ChocoApp.IntuneBody
7- $tenants = if ($chocoapp.Tenant -eq ' AllTenants' ) {
7+ $tenants = if ($chocoapp.Tenant -eq ' AllTenants' ) {
88 (Get-tenants ).defaultDomainName
99} else {
1010 $chocoapp.Tenant
11- }
11+ }
1212if ($chocoApp.type -eq ' MSPApp' ) {
1313 [xml ]$Intunexml = Get-Content " AddMSPApp\$ ( $ChocoApp.MSPAppName ) .app.xml"
1414 $intunewinFilesize = (Get-Item " AddMSPApp\$ ( $ChocoApp.MSPAppName ) .intunewin" )
@@ -25,7 +25,7 @@ $ContentBody = ConvertTo-Json @{
2525 name = $intunexml.ApplicationInfo.FileName
2626 size = [int64 ]$intunexml.ApplicationInfo.UnencryptedContentSize
2727 sizeEncrypted = [int64 ]($intunewinFilesize ).length
28- }
28+ }
2929$ClearRow = Get-CIPPAzDataTableEntity @Table - Filter $Filter
3030$RemoveCacheFile = if ($chocoapp.Tenant -ne ' AllTenants' ) {
3131 Remove-AzDataTableEntity @Table - Entity $clearRow
@@ -54,11 +54,11 @@ foreach ($tenant in $tenants) {
5454 Try {
5555
5656 $ApplicationList = (New-graphGetRequest - Uri $baseuri - tenantid $Tenant ) | Where-Object { $_.DisplayName -eq $ChocoApp.ApplicationName }
57- if ($ApplicationList.displayname.count -ge 1 ) {
57+ if ($ApplicationList.displayname.count -ge 1 ) {
5858 Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " $ ( $ChocoApp.ApplicationName ) exists. Skipping this application" - Sev ' Info'
5959 continue
6060 }
61- if ($chocoApp.type -eq ' WinGet' ) {
61+ if ($chocoApp.type -eq ' WinGet' ) {
6262 Write-Host ' Winget!'
6363 Write-Host ($intuneBody | ConvertTo-Json - Compress)
6464 $NewApp = New-GraphPostRequest - Uri $baseuri - Body ($intuneBody | ConvertTo-Json - Compress) - Type POST - tenantid $tenant
@@ -79,8 +79,8 @@ foreach ($tenant in $tenants) {
7979 $AzFileUri = New-graphGetRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) " - tenantid $tenant
8080 if ($AZfileuri.uploadState -like ' *fail*' ) { break }
8181 Start-Sleep - Milliseconds 300
82- } while ($AzFileUri.AzureStorageUri -eq $null )
83-
82+ } while ($AzFileUri.AzureStorageUri -eq $null )
83+
8484 $chunkSizeInBytes = 4 mb
8585 [byte []]$bytes = [System.IO.File ]::ReadAllBytes($ ($intunewinFilesize.fullname ))
8686 $chunks = [Math ]::Ceiling($bytes.Length / $chunkSizeInBytes )
@@ -89,15 +89,15 @@ foreach ($tenant in $tenants) {
8989 $Upload = Invoke-RestMethod - Uri " $ ( $AzFileUri.azureStorageUri ) &comp=block&blockid=$id " - Method Put - Headers @ {' x-ms-blob-type' = ' BlockBlob' } - InFile $inFile - ContentType ' application/octet-stream'
9090 $ConfirmUpload = Invoke-RestMethod - Uri " $ ( $AzFileUri.azureStorageUri ) &comp=blocklist" - Method Put - Body " <?xml version=`" 1.0`" encoding=`" utf-8`" ?><BlockList><Latest>$id </Latest></BlockList>"
9191 $CommitReq = New-graphPostRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) /commit" - Body $EncBody - Type POST - tenantid $tenant
92-
92+
9393 do {
9494 $CommitStateReq = New-graphGetRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) " - tenantid $tenant
9595 if ($CommitStateReq.uploadState -like ' *fail*' ) {
9696 Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " $ ( $ChocoApp.ApplicationName ) Commit failed. Please check if app uploaded succesful" - Sev ' Warning'
97- break
97+ break
9898 }
9999 Start-Sleep - Milliseconds 300
100- } while ($CommitStateReq.uploadState -eq ' commitFilePending' )
100+ } while ($CommitStateReq.uploadState -eq ' commitFilePending' )
101101 $CommitFinalizeReq = New-graphPostRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) " - tenantid $tenant - Body ' {"@odata.type":"#microsoft.graph.win32lobapp","committedContentVersion":"1"}' - type PATCH
102102 Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " Added Application $ ( $chocoApp.ApplicationName ) " - Sev ' Info'
103103 if ($AssignTo -ne ' On' ) {
@@ -108,7 +108,7 @@ foreach ($tenant in $tenants) {
108108 Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message ' Successfully added Application' - Sev ' Info'
109109 } catch {
110110 " Failed to add Application for $ ( $Tenant ) : $ ( $_.Exception.Message ) "
111- Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " Failed adding Application $ ( $ChocoApp.ApplicationName ) . Error: $ ( $_.Exception.Message ) " - Sev ' Error'
111+ Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " Failed adding Application $ ( $ChocoApp.ApplicationName ) . Error: $ ( $_.Exception.Message ) " - LogData ( Get-CippException - Exception $_ ) - Sev ' Error'
112112 continue
113113 }
114114
0 commit comments