1
1
param ($name )
2
2
$Table = Get-CippTable - tablename ' apps'
3
- $Filter = " PartitionKey eq 'apps' and RowKey eq '$name '"
3
+ $Filter = " PartitionKey eq 'apps' and RowKey eq '$name '"
4
4
Set-Location (Get-Item $PSScriptRoot ).Parent.FullName
5
5
$ChocoApp = (Get-CIPPAzDataTableEntity @Table - filter $Filter ).JSON | ConvertFrom-Json
6
6
$intuneBody = $ChocoApp.IntuneBody
7
- $tenants = if ($chocoapp.Tenant -eq ' AllTenants' ) {
7
+ $tenants = if ($chocoapp.Tenant -eq ' AllTenants' ) {
8
8
(Get-tenants ).defaultDomainName
9
9
} else {
10
10
$chocoapp.Tenant
11
- }
11
+ }
12
12
if ($chocoApp.type -eq ' MSPApp' ) {
13
13
[xml ]$Intunexml = Get-Content " AddMSPApp\$ ( $ChocoApp.MSPAppName ) .app.xml"
14
14
$intunewinFilesize = (Get-Item " AddMSPApp\$ ( $ChocoApp.MSPAppName ) .intunewin" )
@@ -25,7 +25,7 @@ $ContentBody = ConvertTo-Json @{
25
25
name = $intunexml.ApplicationInfo.FileName
26
26
size = [int64 ]$intunexml.ApplicationInfo.UnencryptedContentSize
27
27
sizeEncrypted = [int64 ]($intunewinFilesize ).length
28
- }
28
+ }
29
29
$ClearRow = Get-CIPPAzDataTableEntity @Table - Filter $Filter
30
30
$RemoveCacheFile = if ($chocoapp.Tenant -ne ' AllTenants' ) {
31
31
Remove-AzDataTableEntity @Table - Entity $clearRow
@@ -54,11 +54,11 @@ foreach ($tenant in $tenants) {
54
54
Try {
55
55
56
56
$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 ) {
58
58
Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " $ ( $ChocoApp.ApplicationName ) exists. Skipping this application" - Sev ' Info'
59
59
continue
60
60
}
61
- if ($chocoApp.type -eq ' WinGet' ) {
61
+ if ($chocoApp.type -eq ' WinGet' ) {
62
62
Write-Host ' Winget!'
63
63
Write-Host ($intuneBody | ConvertTo-Json - Compress)
64
64
$NewApp = New-GraphPostRequest - Uri $baseuri - Body ($intuneBody | ConvertTo-Json - Compress) - Type POST - tenantid $tenant
@@ -79,8 +79,8 @@ foreach ($tenant in $tenants) {
79
79
$AzFileUri = New-graphGetRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) " - tenantid $tenant
80
80
if ($AZfileuri.uploadState -like ' *fail*' ) { break }
81
81
Start-Sleep - Milliseconds 300
82
- } while ($AzFileUri.AzureStorageUri -eq $null )
83
-
82
+ } while ($AzFileUri.AzureStorageUri -eq $null )
83
+
84
84
$chunkSizeInBytes = 4 mb
85
85
[byte []]$bytes = [System.IO.File ]::ReadAllBytes($ ($intunewinFilesize.fullname ))
86
86
$chunks = [Math ]::Ceiling($bytes.Length / $chunkSizeInBytes )
@@ -89,15 +89,15 @@ foreach ($tenant in $tenants) {
89
89
$Upload = Invoke-RestMethod - Uri " $ ( $AzFileUri.azureStorageUri ) &comp=block&blockid=$id " - Method Put - Headers @ {' x-ms-blob-type' = ' BlockBlob' } - InFile $inFile - ContentType ' application/octet-stream'
90
90
$ConfirmUpload = Invoke-RestMethod - Uri " $ ( $AzFileUri.azureStorageUri ) &comp=blocklist" - Method Put - Body " <?xml version=`" 1.0`" encoding=`" utf-8`" ?><BlockList><Latest>$id </Latest></BlockList>"
91
91
$CommitReq = New-graphPostRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) /commit" - Body $EncBody - Type POST - tenantid $tenant
92
-
92
+
93
93
do {
94
94
$CommitStateReq = New-graphGetRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) /microsoft.graph.win32lobapp/contentVersions/1/files/$ ( $ContentReq.id ) " - tenantid $tenant
95
95
if ($CommitStateReq.uploadState -like ' *fail*' ) {
96
96
Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " $ ( $ChocoApp.ApplicationName ) Commit failed. Please check if app uploaded succesful" - Sev ' Warning'
97
- break
97
+ break
98
98
}
99
99
Start-Sleep - Milliseconds 300
100
- } while ($CommitStateReq.uploadState -eq ' commitFilePending' )
100
+ } while ($CommitStateReq.uploadState -eq ' commitFilePending' )
101
101
$CommitFinalizeReq = New-graphPostRequest - Uri " $ ( $BaseURI ) /$ ( $NewApp.id ) " - tenantid $tenant - Body ' {"@odata.type":"#microsoft.graph.win32lobapp","committedContentVersion":"1"}' - type PATCH
102
102
Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message " Added Application $ ( $chocoApp.ApplicationName ) " - Sev ' Info'
103
103
if ($AssignTo -ne ' On' ) {
@@ -108,7 +108,7 @@ foreach ($tenant in $tenants) {
108
108
Write-LogMessage - api ' AppUpload' - tenant $ ($Tenant ) - message ' Successfully added Application' - Sev ' Info'
109
109
} catch {
110
110
" 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'
112
112
continue
113
113
}
114
114
0 commit comments