Skip to content

Commit

Permalink
removing some set-locations
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Nov 27, 2023
1 parent 451066f commit 383a28a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 54 deletions.
73 changes: 34 additions & 39 deletions Applications_Upload/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,38 @@ $Filter = "PartitionKey eq 'apps' and RowKey eq '$name'"
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$ChocoApp = (Get-CIPPAzDataTableEntity @Table -filter $Filter).JSON | ConvertFrom-Json
$intuneBody = $ChocoApp.IntuneBody
$tenants = if ($chocoapp.Tenant -eq "AllTenants") {
$tenants = if ($chocoapp.Tenant -eq 'AllTenants') {
(Get-tenants).defaultDomainName
}
else {
} else {
$chocoapp.Tenant
}
if ($chocoApp.type -eq "MSPApp") {
if ($chocoApp.type -eq 'MSPApp') {
[xml]$Intunexml = Get-Content "AddMSPApp\$($ChocoApp.MSPAppName).app.xml"
$intunewinFilesize = (Get-Item "AddMSPApp\$($ChocoApp.MSPAppName).intunewin")
$Infile = "AddMSPApp\$($ChocoApp.MSPAppName).intunewin"
}
else {
[xml]$Intunexml = Get-Content "AddChocoApp\choco.app.xml"
$intunewinFilesize = (Get-Item "AddChocoApp\IntunePackage.intunewin")
} else {
[xml]$Intunexml = Get-Content 'AddChocoApp\choco.app.xml'
$intunewinFilesize = (Get-Item 'AddChocoApp\IntunePackage.intunewin')
$Infile = "AddChocoApp\$($intunexml.ApplicationInfo.FileName)"
}
$assignTo = $ChocoApp.AssignTo
$AssignToIntent = $ChocoApp.InstallationIntent
$Baseuri = "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps"
$Baseuri = 'https://graph.microsoft.com/beta/deviceAppManagement/mobileApps'
$ContentBody = ConvertTo-Json @{
name = $intunexml.ApplicationInfo.FileName
size = [int64]$intunexml.ApplicationInfo.UnencryptedContentSize
sizeEncrypted = [int64]($intunewinFilesize).length
}
$ClearRow = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$RemoveCacheFile = if ($chocoapp.Tenant -ne "AllTenants") {
$RemoveCacheFile = if ($chocoapp.Tenant -ne 'AllTenants') {
Remove-AzDataTableEntity @Table -Entity $clearRow
}
else {
} else {
$Table.Force = $true
Add-CIPPAzDataTableEntity @Table -Entity @{
JSON = "$($ChocoApp | ConvertTo-Json)"
RowKey = "$($ClearRow.RowKey)"
PartitionKey = "apps"
status = "Deployed"
PartitionKey = 'apps'
status = 'Deployed'
}
}
$EncBody = @{
Expand All @@ -58,62 +55,60 @@ foreach ($tenant in $tenants) {

$ApplicationList = (New-graphGetRequest -Uri $baseuri -tenantid $Tenant) | Where-Object { $_.DisplayName -eq $ChocoApp.ApplicationName }
if ($ApplicationList.displayname.count -ge 1) {
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) exists. Skipping this application" -Sev "Info"
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) exists. Skipping this application" -Sev 'Info'
continue
}
if ($chocoApp.type -eq "WinGet") {
Write-Host "Winget!"
if ($chocoApp.type -eq 'WinGet') {
Write-Host 'Winget!'
Write-Host ($intuneBody | ConvertTo-Json -Compress)
$NewApp = New-GraphPostRequest -Uri $baseuri -Body ($intuneBody | ConvertTo-Json -Compress) -Type POST -tenantid $tenant
Start-Sleep -Milliseconds 200
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) uploaded as WinGet app." -Sev "Info"
if ($AssignTo -ne "On") {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) uploaded as WinGet app." -Sev 'Info'
if ($AssignTo -ne 'On') {
$intent = if ($AssignToIntent) { 'Uninstall' } else { 'Required' }
Set-CIPPAssignedApplication -ApplicationId $NewApp.Id -Intent $intent -TenantFilter $tenant -groupName "$AssignTo" -AppType "WinGet"
Set-CIPPAssignedApplication -ApplicationId $NewApp.Id -Intent $intent -TenantFilter $tenant -groupName "$AssignTo" -AppType 'WinGet'
}
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Successfully created" -Sev "Info"
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Successfully created" -Sev 'Info'
exit 0
}
else {
} else {
$NewApp = New-GraphPostRequest -Uri $baseuri -Body ($intuneBody | ConvertTo-Json) -Type POST -tenantid $tenant

}
$ContentReq = New-GraphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/" -Body $ContentBody -Type POST -tenantid $tenant
do {
$AzFileUri = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
if ($AZfileuri.uploadState -like "*fail*") { break }
$AzFileUri = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
if ($AZfileuri.uploadState -like '*fail*') { break }
Start-Sleep -Milliseconds 300
} while ($AzFileUri.AzureStorageUri -eq $null)

$chunkSizeInBytes = 4mb
[byte[]]$bytes = [System.IO.File]::ReadAllBytes($($intunewinFilesize.fullname))
$chunks = [Math]::Ceiling($bytes.Length / $chunkSizeInBytes);
$id = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($chunks.ToString("0000")))
$chunks = [Math]::Ceiling($bytes.Length / $chunkSizeInBytes)
$id = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($chunks.ToString('0000')))
#For anyone that reads this, The maximum chunk size is 100MB for blob storage, so we can upload it as one part and just give it the single ID. Easy :)
$Upload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=block&blockid=$id" -Method Put -Headers @{'x-ms-blob-type' = 'BlockBlob' } -InFile $inFile -ContentType "application/octet-stream"
$Upload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=block&blockid=$id" -Method Put -Headers @{'x-ms-blob-type' = 'BlockBlob' } -InFile $inFile -ContentType 'application/octet-stream'
$ConfirmUpload = Invoke-RestMethod -Uri "$($AzFileUri.azureStorageUri)&comp=blocklist" -Method Put -Body "<?xml version=`"1.0`" encoding=`"utf-8`"?><BlockList><Latest>$id</Latest></BlockList>"
$CommitReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)/commit" -Body $EncBody -Type POST -tenantid $tenant
$CommitReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)/commit" -Body $EncBody -Type POST -tenantid $tenant

do {
$CommitStateReq = New-graphGetRequest -Uri "$($BaseURI)/$($NewApp.id)/microsoft.graph.win32lobapp/contentVersions/1/files/$($ContentReq.id)" -tenantid $tenant
if ($CommitStateReq.uploadState -like "*fail*") {
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Commit failed. Please check if app uploaded succesful" -Sev "Warning"
if ($CommitStateReq.uploadState -like '*fail*') {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "$($ChocoApp.ApplicationName) Commit failed. Please check if app uploaded succesful" -Sev 'Warning'
break
}
Start-Sleep -Milliseconds 300
} while ($CommitStateReq.uploadState -eq "commitFilePending")
} while ($CommitStateReq.uploadState -eq 'commitFilePending')
$CommitFinalizeReq = New-graphPostRequest -Uri "$($BaseURI)/$($NewApp.id)" -tenantid $tenant -Body '{"@odata.type":"#microsoft.graph.win32lobapp","committedContentVersion":"1"}' -type PATCH
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "Added Application $($chocoApp.ApplicationName)" -Sev "Info"
if ($AssignTo -ne "On") {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Added Application $($chocoApp.ApplicationName)" -Sev 'Info'
if ($AssignTo -ne 'On') {
$intent = if ($AssignToIntent) { 'Uninstall' } else { 'Required' }
Set-CIPPAssignedApplication -ApplicationId $NewApp.Id -Intent $intent -TenantFilter $tenant -groupName "$AssignTo" -AppType "Win32Lob"
Set-CIPPAssignedApplication -ApplicationId $NewApp.Id -Intent $intent -TenantFilter $tenant -groupName "$AssignTo" -AppType 'Win32Lob'

}
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "Successfully added Application" -Sev "Info"
}
catch {
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message 'Successfully added Application' -Sev 'Info'
} catch {
"Failed to add Application for $($Tenant): $($_.Exception.Message)"
Write-LogMessage -api "AppUpload" -tenant $($Tenant) -message "Failed adding Application $($ChocoApp.ApplicationName). Error: $($_.Exception.Message)" -Sev "Error"
Write-LogMessage -api 'AppUpload' -tenant $($Tenant) -message "Failed adding Application $($ChocoApp.ApplicationName). Error: $($_.Exception.Message)" -Sev 'Error'
continue
}

Expand Down
1 change: 0 additions & 1 deletion BestPracticeAnalyser_GetQueue/run.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
param($name)
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
#$Skiplist = (Get-Content ExcludedTenants -ErrorAction SilentlyContinue | ConvertFrom-Csv -Delimiter "|" -Header "name", "date", "user").name
$Tenants = Get-Tenants #Get-Content ".\tenants.cache.json" | ConvertFrom-Json | Where-Object {$Skiplist -notcontains $_.defaultDomainName}

Expand Down
7 changes: 2 additions & 5 deletions DomainAnalyser_List/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

Expand All @@ -29,11 +28,9 @@ try {
$Object
}
}
}
catch {}
} catch {}
}
}
catch {
} catch {
$Results = @()
}

Expand Down
12 changes: 5 additions & 7 deletions Modules/CIPPCore/Public/Remove-CIPPLicense.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ function Remove-CIPPLicense {
$ExecutingUser,
$userid,
$username,
$APIName = "Remove License",
$APIName = 'Remove License',
$TenantFilter
)
Set-Location (Get-Item $PSScriptRoot).FullName
$ConvertTable = Import-Csv Conversiontable.csv
try {
$CurrentLicenses = (New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/$($userid)" -tenantid $tenantFilter).assignedlicenses.skuid
$ConvertedLicense = $(($ConvertTable | Where-Object { $_.guid -in $CurrentLicenses }).'Product_Display_Name' | Sort-Object -Unique) -join ','
$LicensesToRemove = if ($CurrentLicenses) { ConvertTo-Json @( $CurrentLicenses) } else { "[]" }
$LicensesToRemove = if ($CurrentLicenses) { ConvertTo-Json @( $CurrentLicenses) } else { '[]' }
$LicenseBody = '{"addLicenses": [], "removeLicenses": ' + $LicensesToRemove + '}'
$LicRequest = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/users/$($userid)/assignlicense" -tenantid $tenantFilter -type POST -body $LicenseBody -verbose
Write-LogMessage -user $ExecutingUser -API $APIName -message "Removed license for $($username)" -Sev "Info" -tenant $TenantFilter
Write-LogMessage -user $ExecutingUser -API $APIName -message "Removed license for $($username)" -Sev 'Info' -tenant $TenantFilter
Return "Removed current licenses: $ConvertedLicense"

}
catch {
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not remove license for $username" -Sev "Error" -tenant $TenantFilter
} catch {
Write-LogMessage -user $ExecutingUser -API $APIName -message "Could not remove license for $username" -Sev 'Error' -tenant $TenantFilter
return "Could not remove license for $($username). Error: $($_.Exception.Message)"
}
}
4 changes: 2 additions & 2 deletions SendStats/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ param($Timer)
#These stats are sent to a central server to help us understand how many tenants are using the product, and how many are using the latest version, this information allows the CIPP team to make decisions about what features to support, and what features to deprecate.
#We will never ship any data that is related to your instance, all we care about is the number of tenants, and the version of the API you are running, and if you completed setup.

if ($ENV:applicationid -ne "LongApplicationID") {
if ($ENV:applicationid -ne 'LongApplicationID') {
$SetupComplete = $true
}
$TenantCount = (Get-Tenants).count

Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$APIVersion = Get-Content "version_latest.txt" | Out-String
$APIVersion = Get-Content 'version_latest.txt' | Out-String

$SendingObject = [PSCustomObject]@{
rgid = $env:WEBSITE_SITE_NAME
Expand Down

0 comments on commit 383a28a

Please sign in to comment.