Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion d365bap.tools/d365bap.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
, 'Set-UdeDbJitCache'
, 'Set-UdeEnvironmentInSession'

, 'Start-BapDatabaseRefresh'
, 'Start-UdeDatabaseRefresh'
, 'Start-UdeDbSsms'
, 'Switch-BapTenant'

Expand Down
10 changes: 6 additions & 4 deletions d365bap.tools/functions/Clear-UdeOrphanedConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ function Clear-UdeOrphanedConfig {
$colPackageDirs = Get-Item -Path $pathPackages | `
Select-Object -ExpandProperty FullName

# Then we need to find all active package directories - based on the UDE configs
$activePackageDirs = @($colConfigs.PackagesLocalDirectory | `
ForEach-Object { Split-Path -Path $_ -Parent }) | `
Select-Object -Unique
if ($colConfigs.Count -gt 0) {
# Then we need to find all active package directories - based on the UDE configs
$activePackageDirs = @($colConfigs.PackagesLocalDirectory | `
ForEach-Object { Split-Path -Path $_ -Parent }) | `
Select-Object -Unique
}

# Finally, we need to find all orphaned package directories
$colPackageDirs | Where-Object { $_ -notin $activePackageDirs } | ForEach-Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function Confirm-BapEnvironmentIntegration {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
3 changes: 2 additions & 1 deletion d365bap.tools/functions/Get-BapEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ function Get-BapEnvironment {
"Properties.linkedAppMetadata.url as FinOpsMetadataEnvUri",
@{Name = "PpacManagedEnv"; Expression = { $_.Properties.governanceConfiguration.protectionLevel -ne 'Basic' } },
@{Name = "Managed"; Expression = { $_.Properties.governanceConfiguration.protectionLevel -ne 'Basic' } },
"Properties.linkedAppMetadata.url as FnOEnvUri",
@{Name = "FnOEnvUri"; Expression = { $_.Properties.linkedAppMetadata.url -replace "com/", "com" } },
@{Name = "FinOpsEnvUri"; Expression = { $_.Properties.linkedAppMetadata.url -replace "com/", "com" } },
@{Name = "PpacEnvUri"; Expression = { $_.Properties.linkedEnvironmentMetadata.instanceUrl -replace "com/", "com" } },
@{Name = "PpacEnvApiUri"; Expression = { $_.Properties.linkedEnvironmentMetadata.instanceApiUrl -replace "com/", "com" } },
@{Name = "AdminMode"; Expression = { $_.Properties.states.runtime.id -eq "AdminMode" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function Get-BapEnvironmentApplicationUser {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
2 changes: 1 addition & 1 deletion d365bap.tools/functions/Get-BapEnvironmentPowerApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function Get-BapEnvironmentPowerApp {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri
$uriPowerAppsApi = $envObj."Api.PowerApps"

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
Expand Down
2 changes: 1 addition & 1 deletion d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function Get-BapEnvironmentSecurityRole {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
2 changes: 1 addition & 1 deletion d365bap.tools/functions/Get-BapEnvironmentSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function Get-BapEnvironmentSolution {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
2 changes: 1 addition & 1 deletion d365bap.tools/functions/Get-BapEnvironmentUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function Get-BapEnvironmentUser {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function Get-BapEnvironmentVirtualEntity {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
50 changes: 10 additions & 40 deletions d365bap.tools/functions/Get-UdeEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,6 @@ function Get-UdeEnvironment {
}

process {
$SoapBody = @"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<UserType xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">CrmUser</UserType>
<SdkClientVersion xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">9.2.49.6961</SdkClientVersion>
<x-ms-client-request-id xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">##REQUESTID##</x-ms-client-request-id>
</s:Header>
<s:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
<request xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
<a:RequestId>##REQUESTID##</a:RequestId>
<a:RequestName>msprov_getfinopsapplicationdetails</a:RequestName>
</request>
</Execute>
</s:Body>
</s:Envelope>
"@

$resCol = @(
foreach ($envObj in $($colEnv | Where-Object FinOpsMetadataEnvType -eq "Internal")) {
if ($searchById) {
Expand All @@ -103,42 +84,31 @@ function Get-UdeEnvironment {
}

# We need to get the internal provisioning details via SOAP call
$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri
$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken

$payload = $SoapBody -replace "##REQUESTID##", ([System.Guid]::NewGuid().ToString())
$localUri = "$($baseUri)/XRMServices/2011/Organization.svc/web?SDKClientVersion=9.2.49.6961"

$headers = @{
"Content-Type" = "text/xml; charset=utf-8"
"Authorization" = "Bearer $($tokenWebApiValue)"
"Soapaction" = "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute"
}

$Response = Invoke-WebRequest -Uri $localUri `
-Method Post `
$localUri = $baseUri + '/api/data/v9.2/msprov_getfinopsapplicationdetails'

$Response = Invoke-RestMethod -Uri $localUri `
-Method Get `
-Headers $headers `
-Body $payload `
-UseBasicParsing `
-SkipHttpErrorCheck

if (-not ($Response.StatusCode -like "2**")) {
if ($null -eq $Response) {
$messageString = "Could not obtain the <c='em'>Ppac Provision</c> details for <c='em'>$($envObj.PpacEnvName)</c>. It could be due to insufficient permissions or the environment not being fully provisioned. Please try to access the environment details from PowerPlatform Admin Center."
Write-PSFMessage -Level Important -Message $messageString
Write-PSFHostColor -String "- <c='em'>https://admin.powerplatform.microsoft.com/environments/environment/$($envObj.PpacEnvId)/hub</c>"
}
else {
$tmpXml = [xml]$Response.Content
$nodes = $tmpXml.SelectNodes('//*[local-name()="KeyValuePairOfstringanyType"]')

foreach ($node in $nodes) {
$keyNode = $node.SelectSingleNode('*[local-name()="key"]')
$valueNode = $node.SelectSingleNode('*[local-name()="value"]')

$propName = $($keyNode.InnerText).Replace("applicationversion", "AppVersion").Replace("platformversion", "PlatVersion").Replace("finopsenvironmentstate", "State").Replace("applicationdeploymenttype", "Type").Replace("finopsenvironmentid", "Id")
$envObj | Add-Member -NotePropertyName "Provisioning$($propName)" -NotePropertyValue $valueNode.InnerText
}
$envObj | Add-Member -NotePropertyName "ProvisioningAppVersion" -NotePropertyValue $Response.applicationversion
$envObj | Add-Member -NotePropertyName "ProvisioningPlatVersion" -NotePropertyValue $Response.platformversion
$envObj | Add-Member -NotePropertyName "ProvisioningState" -NotePropertyValue $Response.finopsenvironmentstate
$envObj | Add-Member -NotePropertyName "ProvisioningType" -NotePropertyValue $Response.applicationdeploymenttype
}

# We need to user friendly version details from the installed D365 app
Expand Down
10 changes: 6 additions & 4 deletions d365bap.tools/functions/Get-UdeEnvironmentOperationHistory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function Get-UdeEnvironmentOperationHistory {
}

foreach ($opsObj in $colModules) {
foreach ($prop in ($opsObj.msprov_operationproperties | `
foreach ($prop in ($opsObj.msprov_operationproperties | Where-Object { $null -ne $_ } |`
ConvertFrom-Json -Depth 10).PsObject.Properties) {
$opsObj | Add-Member -NotePropertyName "prop_$($prop.Name)" -NotePropertyValue $prop.Value -Force
}
Expand Down Expand Up @@ -152,7 +152,6 @@ function Get-UdeEnvironmentOperationHistory {
if ($DownloadLog) {
Write-PSFMessage `
-Message "Please note that for '<c='em'>FnO DB Sql Jit request</c>' there exists no logs. Will attempt to download logs for other operations." `


foreach ($histObj in $resCol) {
$logFileName = "$($histObj.Id)_$($histObj.msprov_logs_name)"
Expand All @@ -165,11 +164,14 @@ function Get-UdeEnvironmentOperationHistory {
Invoke-WebRequest -Uri $logUri `
-Method Get `
-Headers $headers `
-OutFile $downloadFilePath
-OutFile $downloadFilePath `
-SkipHttpErrorCheck
}
}
}

Write-PSFMessage -Level Important -Message "Operation logs downloaded to:"
Write-PSFHostColor -String "- '<c='em'>$downloadDir</c>'"
}

$resCol
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Set-BapEnvironmentSecurityRoleMember {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function Set-BapEnvironmentVirtualEntity {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,36 @@
Instructs the cmdlet to execute an advanced copy for Finance and Operations.

.EXAMPLE
PS C:\> Start-BapDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat*
PS C:\> Start-UdeDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat*

This will start a full copy database refresh from the environment with id containing "dev" to the environment with id containing "uat".
It defaults to a full copy.

.EXAMPLE
PS C:\> Start-BapDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy
PS C:\> Start-UdeDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy

This will start a full copy database refresh from the environment with id containing "dev" to the environment with id containing "uat".

.EXAMPLE
PS C:\> Start-BapDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType TransactionLess
PS C:\> Start-UdeDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType TransactionLess

This will start a transaction-less database refresh from the environment with id containing "dev" to the environment with id containing "uat".

.EXAMPLE
PS C:\> Start-BapDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy -IncludeAuditData
PS C:\> Start-UdeDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy -IncludeAuditData

This will start a full copy database refresh from the environment with id containing "dev" to the environment with id containing "uat".
It will include audit data in the copy.

.EXAMPLE
PS C:\> Start-BapDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy -AdvancedFnO
PS C:\> Start-UdeDatabaseRefresh -SourceEnvironmentId *dev* -TargetEnvironmentId *uat* -CopyType FullCopy -AdvancedFnO
This will start a full copy database refresh from the environment with id containing "dev" to the environment with id containing "uat".
It will execute an advanced copy for Finance and Operations.

.NOTES
Author: Mötz Jensen (@Splaxi)
#>
function Start-BapDatabaseRefresh {
function Start-UdeDatabaseRefresh {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[CmdletBinding()]
param (
Expand Down Expand Up @@ -88,8 +88,8 @@ function Start-BapDatabaseRefresh {
process {
if (Test-PSFFunctionInterrupt) { return }

$envSource = Get-BapEnvironment -EnvironmentId $SourceEnvironmentId | Select-Object -First 1
$envTarget = Get-BapEnvironment -EnvironmentId $TargetEnvironmentId | Select-Object -First 1
$envSource = Get-UdeEnvironment -EnvironmentId $SourceEnvironmentId | Select-Object -First 1
$envTarget = Get-UdeEnvironment -EnvironmentId $TargetEnvironmentId | Select-Object -First 1

if ($null -eq $envSource -or $null -eq $envTarget) {
$messageString = "Could not find either <c='em'>source</c> or <c='em'>target</c> environments. Please verify the Ids and try again, or list available environments using <c='em'>Get-BapEnvironment</c>."
Expand All @@ -109,6 +109,15 @@ function Start-BapDatabaseRefresh {
return
}

if (([Version]$envSource.FinOpsApp).Build -lt ([Version]$envTarget.FinOpsApp).Build) {
$messageString = "The build version of FnO application in the source environment is <c='em'>lower</c> than in the target environment. Database refresh is not supported in this scenario."

Write-PSFMessage -Level Important -Message $messageString
Stop-PSFFunction -Message "Stopping because one of the FnO application is different." `
-Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
return
}

$payload = [PSCustomObject][ordered]@{
sourceEnvironmentId = $envSource.PpacEnvId
targetEnvironmentName = $envTarget.PpacEnvName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Update-BapEnvironmentVirtualEntityMetadata {

if (Test-PSFFunctionInterrupt) { return }

$baseUri = $envObj.LinkedMetaPpacEnvUri
$baseUri = $envObj.PpacEnvUri

$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
Expand Down
14 changes: 7 additions & 7 deletions d365bap.tools/tests/functions/Start-BapDatabaseRefresh.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Describe "Start-BapDatabaseRefresh Unit Tests" -Tag "Unit" {
Describe "Start-UdeDatabaseRefresh Unit Tests" -Tag "Unit" {
BeforeAll {
# Place here all things needed to prepare for the tests
}
Expand All @@ -8,11 +8,11 @@

Describe "Ensuring unchanged command signature" {
It "should have the expected parameter sets" {
(Get-Command Start-BapDatabaseRefresh).ParameterSets.Name | Should -Be '__AllParameterSets'
(Get-Command Start-UdeDatabaseRefresh).ParameterSets.Name | Should -Be '__AllParameterSets'
}

It 'Should have the expected parameter SourceEnvironmentId' {
$parameter = (Get-Command Start-BapDatabaseRefresh).Parameters['SourceEnvironmentId']
$parameter = (Get-Command Start-UdeDatabaseRefresh).Parameters['SourceEnvironmentId']
$parameter.Name | Should -Be 'SourceEnvironmentId'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
Expand All @@ -25,7 +25,7 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter TargetEnvironmentId' {
$parameter = (Get-Command Start-BapDatabaseRefresh).Parameters['TargetEnvironmentId']
$parameter = (Get-Command Start-UdeDatabaseRefresh).Parameters['TargetEnvironmentId']
$parameter.Name | Should -Be 'TargetEnvironmentId'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
Expand All @@ -38,7 +38,7 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter CopyType' {
$parameter = (Get-Command Start-BapDatabaseRefresh).Parameters['CopyType']
$parameter = (Get-Command Start-UdeDatabaseRefresh).Parameters['CopyType']
$parameter.Name | Should -Be 'CopyType'
$parameter.ParameterType.ToString() | Should -Be System.String
$parameter.IsDynamic | Should -Be $False
Expand All @@ -51,7 +51,7 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter IncludeAuditData' {
$parameter = (Get-Command Start-BapDatabaseRefresh).Parameters['IncludeAuditData']
$parameter = (Get-Command Start-UdeDatabaseRefresh).Parameters['IncludeAuditData']
$parameter.Name | Should -Be 'IncludeAuditData'
$parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter
$parameter.IsDynamic | Should -Be $False
Expand All @@ -64,7 +64,7 @@
$parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter AdvancedFnO' {
$parameter = (Get-Command Start-BapDatabaseRefresh).Parameters['AdvancedFnO']
$parameter = (Get-Command Start-UdeDatabaseRefresh).Parameters['AdvancedFnO']
$parameter.Name | Should -Be 'AdvancedFnO'
$parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter
$parameter.IsDynamic | Should -Be $False
Expand Down
Loading
Loading