3 new functions
This commit is contained in:
Родитель
63ac1ade97
Коммит
4fccddd2e6
|
@ -34,9 +34,11 @@ function Remove-BcDatabase {
|
|||
else {
|
||||
$op = "="
|
||||
}
|
||||
$dbFiles = Invoke-SqlCmd `
|
||||
-ServerInstance $databaseserverinstance `
|
||||
-Query "SELECT f.physical_name FROM sys.sysdatabases db INNER JOIN sys.master_files f ON f.database_id = db.dbid WHERE db.name $op '$DatabaseName'" | ForEach-Object { $_.physical_name }
|
||||
if ($databaseServer -eq "localhost") {
|
||||
$dbFiles = Invoke-SqlCmd `
|
||||
-ServerInstance $databaseserverinstance `
|
||||
-Query "SELECT f.physical_name FROM sys.sysdatabases db INNER JOIN sys.master_files f ON f.database_id = db.dbid WHERE db.name $op '$DatabaseName'" | ForEach-Object { $_.physical_name }
|
||||
}
|
||||
|
||||
$databases = Invoke-SqlCmd `
|
||||
-ServerInstance $databaseserverinstance `
|
||||
|
@ -55,11 +57,13 @@ function Remove-BcDatabase {
|
|||
-Query "DROP DATABASE [$_]"
|
||||
}
|
||||
|
||||
$dbFiles | ForEach-Object {
|
||||
if (Test-Path $_) { Remove-Item -Path $_ -Force }
|
||||
$dirname = [System.IO.Path]::GetDirectoryName($_)
|
||||
if ((Get-ChildItem -Path $dirname | Measure-Object).Count -eq 0) {
|
||||
Remove-Item -Path $dirname -Force
|
||||
if ($databaseServer -eq "localhost") {
|
||||
$dbFiles | ForEach-Object {
|
||||
if (Test-Path $_) { Remove-Item -Path $_ -Force }
|
||||
$dirname = [System.IO.Path]::GetDirectoryName($_)
|
||||
if ((Get-ChildItem -Path $dirname | Measure-Object).Count -eq 0) {
|
||||
Remove-Item -Path $dirname -Force
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,9 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder',
|
|||
'Create-MyDeltaFolder', 'Create-MyOriginalFolder',
|
||||
'Create-AadAppsForNav', 'Create-AadUsersInBcContainer',
|
||||
'New-BcAuthContext', 'Renew-BcAuthContext', 'Get-BcEnvironments', 'Get-BcPublishedApps',
|
||||
'Install-BcAppFromAppSource', 'New-BcEnvironment', 'Remove-BcEnvironment', 'Set-BcEnvironmentApplicationInsightsKey',
|
||||
'Get-BcInstalledExtensions', 'Install-BcAppFromAppSource', 'New-BcEnvironment',
|
||||
'Remove-BcEnvironment', 'Set-BcEnvironmentApplicationInsightsKey',
|
||||
'New-BcDatabaseExport', 'Get-BcDatabaseExportHistory',
|
||||
'Download-Artifacts', 'Download-File', 'Enter-BcContainer',
|
||||
'Export-BcContainerDatabasesAsBacpac', 'Restore-BcDatabaseFromArtifacts',
|
||||
'Remove-BcDatabase.ps1', 'Export-ModifiedObjectsAsDeltas', 'Export-NavContainerObjects',
|
||||
|
|
|
@ -273,11 +273,14 @@ Check-BcContainerHelperPermissions -Silent
|
|||
. (Join-Path $PSScriptRoot "BcSaaS\Renew-BcAuthContext.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Get-BcEnvironments.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Get-BcPublishedApps.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Get-BcInstalledExtensions.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Install-BcAppFromAppSource")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Publish-PerTenantExtensionApps.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\New-BcEnvironment.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Remove-BcEnvironment.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Set-BcEnvironmentApplicationInsightsKey.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\Get-BcDatabaseExportHistory.ps1")
|
||||
. (Join-Path $PSScriptRoot "BcSaaS\New-BcDatabaseExport.ps1")
|
||||
|
||||
# Azure VM specific functions
|
||||
. (Join-Path $PSScriptRoot "AzureVM\Replace-NavServerContainer.ps1")
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Function for retrieving Database Export History from an online Business Central environment
|
||||
.Description
|
||||
Function for retrieving Database Export History from an online Business Central environment
|
||||
Wrapper for https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api#get-export-history
|
||||
.Parameter bcAuthContext
|
||||
Authorization Context created by New-BcAuthContext.
|
||||
.Parameter applicationFamily
|
||||
Application Family in which the environment is located. Default is BusinessCentral.
|
||||
.Parameter environment
|
||||
Environment from which you want to return the published Apps.
|
||||
.Parameter startTime
|
||||
start time for the query (get export history from this time)
|
||||
.Parameter endTime
|
||||
end time for the query (get export history until this time)
|
||||
.Example
|
||||
$authContext = New-BcAuthContext -includeDeviceLogin
|
||||
Get-BcDatabaseExportHistory -bcAuthContext $authContext
|
||||
#>
|
||||
function Get-BcDatabaseExportHistory {
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[Hashtable] $bcAuthContext,
|
||||
[string] $applicationFamily = "BusinessCentral",
|
||||
[string] $environment = "*",
|
||||
[DateTime] $startTime = (Get-Date).AddDays(-1),
|
||||
[DateTime] $endTime = (Get-Date).AddDays(1)
|
||||
)
|
||||
|
||||
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
|
||||
$bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)"
|
||||
$headers = @{ "Authorization" = $bearerAuthValue }
|
||||
try {
|
||||
(Invoke-RestMethod -Method Get -Uri "https://api.businesscentral.dynamics.com/admin/v2.1/exports/history?start=$startTime&end=$endTime" -Headers $headers).value | Where-Object { $_.environmentName -like $environment }
|
||||
}
|
||||
catch {
|
||||
throw (GetExtenedErrorMessage $_.Exception)
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-BcDatabaseExportHistory
|
|
@ -22,6 +22,11 @@ function Get-BcEnvironments {
|
|||
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
|
||||
$bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)"
|
||||
$headers = @{ "Authorization" = $bearerAuthValue }
|
||||
(Invoke-RestMethod -Method Get -UseBasicParsing -Uri "https://api.businesscentral.dynamics.com/admin/v2.3/applications/$applicationFamily/environments" -Headers $headers).Value
|
||||
try {
|
||||
(Invoke-RestMethod -Method Get -UseBasicParsing -Uri "https://api.businesscentral.dynamics.com/admin/v2.3/applications/$applicationFamily/environments" -Headers $headers).Value
|
||||
}
|
||||
catch {
|
||||
throw (GetExtenedErrorMessage $_.Exception)
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-BcEnvironments
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Function for retrieving Installed Extensions from an online Business Central environment (both AppSource and PTEs)
|
||||
.Description
|
||||
Function for retrieving Installed Extensions from an online Business Central environment (both AppSource and PTEs)
|
||||
.Parameter bcAuthContext
|
||||
Authorization Context created by New-BcAuthContext.
|
||||
.Parameter applicationFamily
|
||||
Application Family in which the environment is located. Default is BusinessCentral.
|
||||
.Parameter companyName
|
||||
CompanyName to use in the request. Default is the first company.
|
||||
.Parameter environment
|
||||
Environment from which you want to return the published Apps.
|
||||
.Example
|
||||
$authContext = New-BcAuthContext -includeDeviceLogin
|
||||
Get-BcInstalledExtensions -bcAuthContext $authContext -environment "Sandbox"
|
||||
#>
|
||||
function Get-BcInstalledExtensions {
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[Hashtable] $bcAuthContext,
|
||||
[string] $applicationFamily = "BusinessCentral",
|
||||
[string] $companyName = "",
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $environment
|
||||
)
|
||||
|
||||
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
|
||||
$bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)"
|
||||
$headers = @{ "Authorization" = $bearerAuthValue }
|
||||
|
||||
$baseUrl = "https://api.businesscentral.dynamics.com/v2.0/$environment/api/microsoft/automation/v1.0"
|
||||
|
||||
$companies = Invoke-RestMethod -Headers $headers -Method Get -Uri "$baseurl/companies" -UseBasicParsing
|
||||
$company = $companies.value | Where-Object { ($companyName -eq "") -or ($_.name -eq $companyName) } | Select-Object -First 1
|
||||
if (!($company)) {
|
||||
throw "No company $companyName"
|
||||
}
|
||||
$companyId = $company.id
|
||||
try {
|
||||
(Invoke-RestMethod -Headers $headers -Method Get -Uri "$baseUrl/companies($companyId)/extensions" -UseBasicParsing).value
|
||||
}
|
||||
catch {
|
||||
throw (GetExtenedErrorMessage $_.Exception)
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-BcInstalledExtensions
|
|
@ -1,8 +1,8 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Function for retrieving Bc Published Apps from an online Business Central environment
|
||||
Function for retrieving Published AppSource Apps from an online Business Central environment
|
||||
.Description
|
||||
Function for retrieving Bc Published Apps from an online Business Central environment
|
||||
Function for retrieving Published AppSource Apps from an online Business Central environment
|
||||
Wrapper for https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api#get-installed-apps
|
||||
.Parameter bcAuthContext
|
||||
Authorization Context created by New-BcAuthContext.
|
||||
|
@ -26,6 +26,11 @@ function Get-BcPublishedApps {
|
|||
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
|
||||
$bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)"
|
||||
$headers = @{ "Authorization" = $bearerAuthValue }
|
||||
(Invoke-RestMethod -Method Get -UseBasicParsing -Uri "https://api.businesscentral.dynamics.com/admin/v2.3/applications/$applicationFamily/environments/$environment/apps" -Headers $headers).Value
|
||||
try {
|
||||
(Invoke-RestMethod -Method Get -UseBasicParsing -Uri "https://api.businesscentral.dynamics.com/admin/v2.3/applications/$applicationFamily/environments/$environment/apps" -Headers $headers).Value
|
||||
}
|
||||
catch {
|
||||
throw (GetExtenedErrorMessage $_.Exception)
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function Get-BcPublishedApps
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<#
|
||||
.Synopsis
|
||||
Function for creating a starting a new Database Export from an online Business Central environment
|
||||
.Description
|
||||
Function for creating a starting a new Database Export from an online Business Central environment
|
||||
Wrapper for https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api#start-environment-database-export
|
||||
.Parameter bcAuthContext
|
||||
Authorization Context created by New-BcAuthContext.
|
||||
.Parameter applicationFamily
|
||||
Application Family in which the environment is located. Default is BusinessCentral.
|
||||
.Parameter environment
|
||||
Environment from which you want to return the published Apps.
|
||||
.Parameter storageAccountSasUri
|
||||
An Azure SAS uri pointing at the Azure storage account where the database will be exported to. The uri must have (Read | Write | Create | Delete) permissions
|
||||
.Parameter blobContainerName
|
||||
The name of the container that will be created by the process to store the exported database.
|
||||
.Parameter blobName
|
||||
The name of the blob within the container that the database will be exported to. Databases are exported in the .bacpac format so a filename ending with the '.bacpac' suffix is typical.
|
||||
.Parameter doNotWait
|
||||
Include this flag if you do not want to wait for the backup to complete
|
||||
.Example
|
||||
$authContext = New-BcAuthContext -includeDeviceLogin
|
||||
New-BcDatabaseExport -bcAuthContext $authContext -environment "Production" -storageAccountSasUri $storageAccountSasUri -blobContainerName $blobContainerName -blobName $blobName -doNotWait
|
||||
#>
|
||||
function New-BcDatabaseExport {
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[Hashtable] $bcAuthContext,
|
||||
[string] $applicationFamily = "BusinessCentral",
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $environment,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $storageAccountSasUri,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $blobContainerName,
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string] $blobName,
|
||||
[switch] $doNotWait
|
||||
)
|
||||
|
||||
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
|
||||
$bearerAuthValue = "Bearer $($bcAuthContext.AccessToken)"
|
||||
$headers = @{ "Authorization" = $bearerAuthValue }
|
||||
$body = @{
|
||||
"storageAccountSasUri" = $storageAccountSasUri
|
||||
"container" = $blobContainerName
|
||||
"blob" = $blobName
|
||||
} | ConvertTo-Json
|
||||
try {
|
||||
Invoke-RestMethod -Method POST -Uri "https://api.businesscentral.dynamics.com/admin/v2.3/exports/applications/$applicationFamily/environments/$environment" -Headers $headers -Body $Body -ContentType 'application/json' -UseBasicParsing
|
||||
}
|
||||
catch {
|
||||
throw (GetExtenedErrorMessage $_.Exception)
|
||||
}
|
||||
if (!$doNotWait) {
|
||||
$uri = [Uri]::new($storageAccountSasUri)
|
||||
$blobUrl = "$($uri.Scheme)://$($uri.Host)/$blobContainerName/$blobName$($uri.Query)"
|
||||
$done = $false
|
||||
Write-Host -NoNewline "Waiting for backup to complete."
|
||||
while (!$done) {
|
||||
Start-Sleep -Seconds 30
|
||||
Write-Host -NoNewline "."
|
||||
try {
|
||||
$result = Invoke-WebRequest -UseBasicParsing -Method Head -Uri $blobUrl -ErrorAction SilentlyContinue
|
||||
if ($result.StatusCode -eq 200) {
|
||||
Write-Host -ForegroundColor Green " Success"
|
||||
$done = $true
|
||||
}
|
||||
else {
|
||||
Write-Host -ForegroundColor red " Failure"
|
||||
throw $result.StatusDescription
|
||||
}
|
||||
}
|
||||
catch {
|
||||
if ($_.exception.response.StatusCode -ne "NotFound") {
|
||||
Write-Host -ForegroundColor red " Failure"
|
||||
throw
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Export-ModuleMember -Function New-BcDatabaseExport
|
|
@ -1,6 +1,9 @@
|
|||
2.0.3
|
||||
Issue #1655 variable $scopes not set
|
||||
Issue #1654 and #1656 Publish-BcContainerApp where the filename contains a comma fails.
|
||||
New Function Get-BcInstalledExtensions to return installed extensions (including PTEs) from an online Business Central environment
|
||||
New function New-BcDatabaseExport to start a new Database Export from an online Business Central environment
|
||||
New function Get-BcDatabaseExportHistory to get the Database Export History from an online Business Central tenant/environment
|
||||
|
||||
2.0.2
|
||||
Allow no credentials with filesOnly containers
|
||||
|
|
Загрузка…
Ссылка в новой задаче