forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpload-PerTenantApp.ps1
40 lines (37 loc) · 1.68 KB
/
Upload-PerTenantApp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function Upload-PerTenantApp
{
param(
[parameter(Mandatory = $true)]
[string]$AppId,
[parameter(Mandatory = $true)]
[string]$AppSecret,
[pscredential]$Credentials=(Get-Credentials -Message "Enter credentials for BC"),
[parameter(Mandatory = $true)]
[string]$Tenant,
$APIUri = 'api/microsoft/automation/beta',
$APIVersion = 'v1.0',
$AppPath,
$Environment,
[Switch]
$WaitForResult
)
#Get token
Write-Host "Getting OAuth token..."
$Token = Get-OAuth2 -AppId $AppId -AppSecret $AppSecret -Credentials $Credentials -Tenant $Tenant
#Get companies
Write-Host "Getting companies..."
$Companies = Get-BCAPIData -OAuthToken $Token -Tenant $Tenant -APIUri $APIUri -Query 'companies' -Environment $Environment -APIVersion $APIVersion
#Upload the app
$CompanyID = $Companies[0].id
$CompanyName = $Companies[0].name
Write-Host "Getting uploading extension to company $CompanyID ($CompanyName)..."
$AppContent = [IO.File]::ReadAllBytes($AppPath)
$Result = Patch-BCAPIData -OAuthToken $Token -Tenant $Tenant -APIUri $APIUri -Query "companies($CompanyID)/extensionUpload(0)/content" -Body $AppContent -Environment $Environment -APIVersion $APIVersion
if ($WaitForResult) {
do {
Start-Sleep -Seconds 10
$Status = Get-ALAppPublicationStatus -AppId $AppId -AppSecret $AppSecret -Credentials $Credentials -Tenant $Tenant -APIUri $APIUri -APIVersion $APIVersion -Token $Token -Environment $Environment -CompanyID $CompanyID
} while ($Status.status -eq 'InProgress')
}
return $Result
}