Skip to content

Commit 3182344

Browse files
authored
Merge pull request #51 from d365collaborative/development
next release
2 parents 0f0f1d6 + ba695d3 commit 3182344

16 files changed

+769
-84
lines changed

d365bap.tools/d365bap.tools.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
, 'Get-BapEnvironment'
5959
, 'Get-BapEnvironmentApplicationUser'
6060
, 'Get-BapEnvironmentD365App'
61+
, 'Get-BapEnvironmentFnOAppUpdate'
6162
, 'Get-BapEnvironmentLinkEnterprisePolicy'
6263
, 'Get-BapEnvironmentOperation'
6364
, 'Get-BapEnvironmentPowerApp'
@@ -87,6 +88,7 @@
8788
, 'Get-UdeVsPowerPlatformExtensionHistory'
8889
, 'Get-UdeXrefDb'
8990

91+
, 'Invoke-BapEnvironmentFnOAppUpdate'
9092
, 'Invoke-BapEnvironmentInstallD365App'
9193
, 'Invoke-BapInstallAzCopy'
9294

d365bap.tools/functions/Get-BapEnvironment.ps1

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
1414
Default value is "*" - which translates into all available environments
1515
16+
.PARAMETER FnOEnabled
17+
Instruct the cmdlet to only return environments that have Finance and Operations enabled
18+
1619
.PARAMETER AsExcelOutput
1720
Instruct the cmdlet to output all details directly to an Excel file
1821
@@ -22,35 +25,24 @@
2225
PS C:\> Get-BapEnvironment
2326
2427
This will query for ALL available environments.
25-
26-
Sample output:
27-
PpacEnvId PpacEnvRegion PpacEnvName PpacEnvSku LinkedAppLcsEnvUri
28-
--------- ------------- ----------- ---------- ------------------
29-
32c6b196-ef52-4c43-93cf-6ecba51e6aa1 europe new-uat Sandbox https://new-uat.sandbox.operatio...
30-
eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 europe new-test Sandbox https://new-test.sandbox.operati...
31-
d45936a7-0408-4b79-94d1-19e4c6e5a52e europe new-golden Sandbox https://new-golden.sandbox.opera...
32-
Default-e210bc90-e54b-4544-a9b8-b123 europe New Customer Default
28+
It will include both PPAC and FinOps enabled environments.
3329
30+
.EXAMPLE
31+
PS C:\> Get-BapEnvironment -FnOEnabled
32+
33+
This will query for ALL available environments.
34+
It will ONLY include FinOps enabled environments.
35+
3436
.EXAMPLE
3537
PS C:\> Get-BapEnvironment -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6
3638
3739
This will query for the specific environment.
3840
39-
Sample output:
40-
PpacEnvId PpacRegion PpacName PpacSku LinkedAppLcsEnvUri
41-
--------- ------------- ----------- ---------- ------------------
42-
eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 europe new-test Sandbox https://new-test.sandbox.operati...
43-
4441
.EXAMPLE
4542
PS C:\> Get-BapEnvironment -EnvironmentId *test*
4643
4744
This will query for the specific environment, using a wildcard search.
4845
49-
Sample output:
50-
PpacEnvId PpacRegion PpacName PpacSku LinkedAppLcsEnvUri
51-
--------- ------------- ----------- ---------- ------------------
52-
eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 europe new-test Sandbox https://new-test.sandbox.operati...
53-
5446
.EXAMPLE
5547
PS C:\> Get-BapEnvironment -AsExcelOutput
5648
@@ -66,6 +58,8 @@ function Get-BapEnvironment {
6658
param (
6759
[string] $EnvironmentId = "*",
6860

61+
[switch] $FnOEnabled,
62+
6963
[switch] $AsExcelOutput
7064
)
7165

@@ -77,7 +71,10 @@ function Get-BapEnvironment {
7771
"Authorization" = "Bearer $($tokenBapValue)"
7872
}
7973

80-
$resEnvs = Invoke-RestMethod -Method Get -Uri "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments?api-version=2023-06-01" -Headers $headersBapApi | Select-Object -ExpandProperty Value
74+
$resEnvs = Invoke-RestMethod -Method Get `
75+
-Uri "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments?api-version=2023-06-01" `
76+
-Headers $headersBapApi | `
77+
Select-Object -ExpandProperty Value
8178

8279
$searchById = Test-Guid -InputObject $EnvironmentId
8380
}
@@ -152,10 +149,33 @@ function Get-BapEnvironment {
152149
}
153150
}
154151
},
155-
"*"
152+
@{Name = "FnOEnvType"; Expression = {
153+
$uri = $_.Properties.linkedAppMetadata.url
154+
switch ($_.Properties.linkedAppMetadata.type) {
155+
"Internal" { "UDE/USE" }
156+
"Linked" {
157+
if ($uri -like "*axcloud*") {
158+
"LcsDevbox"
159+
}
160+
elseif ($uri -like "*sandbox*") {
161+
"LcsSandbox"
162+
}
163+
else {
164+
"LcsProduction"
165+
}
166+
}
167+
Default { "N/A" }
168+
}
169+
}
170+
},
171+
*
156172
}
157173
)
158174

175+
if ($FnOEnabled) {
176+
$resCol = $resCol | Where-Object { $null -ne $_.FinOpsMetadataEnvType }
177+
}
178+
159179
if ($AsExcelOutput) {
160180
$resCol | Export-Excel -WorksheetName "Get-BapEnvironment" `
161181
-NoNumberConversion Version, AvailableVersion, InstalledVersion, crmMinversion, crmMaxVersion, Version
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
<#
3+
.SYNOPSIS
4+
Get FnO/FinOps Application update versions.
5+
6+
.DESCRIPTION
7+
Retrieves available FnO/FinOps Application update versions for a given environment.
8+
9+
.PARAMETER EnvironmentId
10+
The id of the environment that you want to work against.
11+
12+
.PARAMETER Oldest
13+
Instructs the function to return only the oldest available version.
14+
15+
.PARAMETER Latest
16+
Instructs the function to return only the latest available version.
17+
18+
.EXAMPLE
19+
PS C:\> Get-BapEnvironmentFnOAppUpdate -EnvironmentId "env-123"
20+
21+
This will retrieve all available FnO/FinOps Application update versions for the specified environment.
22+
23+
.EXAMPLE
24+
PS C:\> Get-BapEnvironmentFnOAppUpdate -EnvironmentId "env-123" -Latest
25+
26+
This will retrieve the latest available FnO/FinOps Application update version for the specified environment.
27+
28+
.EXAMPLE
29+
PS C:\> Get-BapEnvironmentFnOAppUpdate -EnvironmentId "env-123" -Oldest
30+
31+
This will retrieve the oldest available FnO/FinOps Application update version for the specified environment.
32+
33+
.NOTES
34+
Author: Mötz Jensen (@Splaxi)
35+
#>
36+
function Get-BapEnvironmentFnOAppUpdate {
37+
[CmdletBinding(DefaultParameterSetName = 'Default')]
38+
[OutputType('System.Object[]')]
39+
param (
40+
[Parameter (Mandatory = $true)]
41+
[string] $EnvironmentId,
42+
43+
[Parameter (ParameterSetName = "Lowest")]
44+
[switch] $Oldest,
45+
46+
[Parameter (ParameterSetName = "Highest")]
47+
[switch] $Latest
48+
)
49+
50+
begin {
51+
# Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything.
52+
$envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1
53+
54+
if ($null -eq $envObj) {
55+
$messageString = "The supplied EnvironmentId: <c='em'>$EnvironmentId</c> didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the <c='em'>Get-BapEnvironment</c> cmdlet."
56+
Write-PSFMessage -Level Important -Message $messageString
57+
Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
58+
return
59+
}
60+
61+
$baseUri = $envObj.PpacEnvUri
62+
63+
$secureToken = (Get-AzAccessToken -ResourceUrl $baseUri -AsSecureString).Token
64+
$tokenWebApiValue = ConvertFrom-SecureString -AsPlainText -SecureString $secureToken
65+
66+
$headersWebApi = @{
67+
"Authorization" = "Bearer $($tokenWebApiValue)"
68+
}
69+
}
70+
71+
process {
72+
if (Test-PSFFunctionInterrupt) { return }
73+
74+
$localUri = $baseUri + '/api/data/v9.2/msprov_getfnoversiondetails'
75+
76+
$resVersions = Invoke-RestMethod -Method Get `
77+
-Uri $localUri `
78+
-Headers $headersWebApi | `
79+
Select-Object -ExpandProperty Response | `
80+
ConvertFrom-Json
81+
82+
$resCol = @(
83+
$resVersions | Sort-Object -Property "value" | `
84+
Select-PSFObject -TypeName 'D365Bap.Tools.FnOAppVersion' `
85+
-Property `
86+
@{Name = "EnvironmentId"; Expression = { $envObj.EnvName } }, `
87+
"value as Version"
88+
)
89+
90+
if ($Oldest) {
91+
$resCol | Select-Object -First 1
92+
}
93+
elseif ($Latest) {
94+
$resCol | Select-Object -Last 1
95+
}
96+
else {
97+
$resCol
98+
}
99+
}
100+
101+
end {
102+
103+
}
104+
}

d365bap.tools/functions/Get-UdeEnvironment.ps1

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
<#
33
.SYNOPSIS
4-
Gets UDE environments.
4+
Gets UDE/USE environments.
55
66
.DESCRIPTION
7-
This function retrieves UDE environments.
7+
This function retrieves UDE/USE environments.
88
99
.PARAMETER EnvironmentId
1010
The ID of the environment to retrieve.
@@ -16,47 +16,73 @@
1616
.PARAMETER SkipVersionDetails
1717
Instructs the function to skip retrieving version details.
1818
19-
Will result in faster execution.
19+
Will result in faster execution, but will not include version information and tell you if the environment is UDE or USE.
2020
21+
.PARAMETER UdeOnly
22+
Instructs the function to only return UDE environments.
23+
24+
.PARAMETER UseOnly
25+
Instructs the function to only return USE environments.
26+
2127
.PARAMETER AsExcelOutput
2228
Instructs the function to export the results to an Excel file.
2329
2430
.EXAMPLE
2531
PS C:\> Get-UdeEnvironment
2632
27-
This will retrieve all available UDE environments.
33+
This will retrieve all available UDE/USE environments.
2834
2935
.EXAMPLE
3036
PS C:\> Get-UdeEnvironment -EnvironmentId "env-123"
3137
32-
This will retrieve the UDE environment with the specified environment ID.
38+
This will retrieve the UDE/USE environment with the specified environment ID.
3339
3440
.EXAMPLE
3541
PS C:\> Get-UdeEnvironment -SkipVersionDetails
3642
37-
This will retrieve all available UDE environments without version details.
43+
This will retrieve all available UDE/USE environments without version details.
44+
45+
.EXAMPLE
46+
PS C:\> Get-UdeEnvironment -UdeOnly
47+
48+
This will retrieve only UDE environments.
49+
50+
.EXAMPLE
51+
PS C:\> Get-UdeEnvironment -UseOnly
52+
53+
This will retrieve only USE environments.
3854
3955
.EXAMPLE
4056
PS C:\> Get-UdeEnvironment -AsExcelOutput
4157
42-
This will export the retrieved UDE environments to an Excel file.
58+
This will export the retrieved UDE/USE environments to an Excel file.
4359
4460
.NOTES
4561
Author: Mötz Jensen (@Splaxi)
4662
#>
4763
function Get-UdeEnvironment {
48-
[CmdletBinding()]
64+
[CmdletBinding(DefaultParameterSetName = 'Default')]
4965
[OutputType('System.Object[]')]
5066
param (
67+
[Parameter()]
5168
[string] $EnvironmentId = "*",
5269

70+
[Parameter(ParameterSetName = "SkipVersion")]
5371
[switch] $SkipVersionDetails,
5472

73+
[Parameter(ParameterSetName = "UdeOnly")]
74+
[switch] $UdeOnly,
75+
76+
[Parameter(ParameterSetName = "UseOnly")]
77+
[switch] $UseOnly,
78+
79+
[Parameter()]
5580
[switch] $AsExcelOutput
5681
)
5782

5883
begin {
59-
$colEnv = Get-BapEnvironment -EnvironmentId $EnvironmentId
84+
$colEnv = Get-BapEnvironment -EnvironmentId $EnvironmentId `
85+
-FnOEnabled
6086

6187
$searchById = Test-Guid -InputObject $EnvironmentId
6288

@@ -77,8 +103,7 @@ function Get-UdeEnvironment {
77103
}
78104

79105
if ($SkipVersionDetails) {
80-
$envObj | Select-PSFObject -TypeName "D365Bap.Tools.UdeEnvironmentBasic" `
81-
-Property *
106+
$envObj
82107

83108
continue
84109
}
@@ -120,14 +145,30 @@ function Get-UdeEnvironment {
120145
$envObj | Add-Member -NotePropertyName "FinOpsApp" -NotePropertyValue $appProvision.InstalledVersion
121146

122147
$envObj | Select-PSFObject -TypeName "D365Bap.Tools.UdeEnvironment" `
148+
-ExcludeProperty FnOEnvType `
123149
-Property "ProvisioningAppVersion as PpacProvApp",
124150
"ProvisioningPlatVersion as PpacProvPlatform",
125151
"ProvisioningState as PpacProvState",
126152
"ProvisioningType as PpacProvType",
153+
@{Name = "FnOEnvType"; Expression = {
154+
switch ($_.ProvisioningType) {
155+
"OnlineDev" { "UDE" }
156+
"Sandbox" { "USE" }
157+
Default { "N/A" }
158+
}
159+
}
160+
},
127161
*
128162
}
129163
)
130164

165+
if ($UdeOnly) {
166+
$resCol = $resCol | Where-Object FnOEnvType -eq "UDE"
167+
}
168+
elseif ($UseOnly) {
169+
$resCol = $resCol | Where-Object FnOEnvType -eq "USE"
170+
}
171+
131172
if ($AsExcelOutput) {
132173
$resCol | Export-Excel -WorksheetName "Get-UdeEnvironment"
133174
return

0 commit comments

Comments
 (0)