From d915a20c4ebdad7d4ffaff6c8abecd356834680f Mon Sep 17 00:00:00 2001 From: Florian Hopfner <33372796+FH-Inway@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:44:20 +0000 Subject: [PATCH 1/7] Update path to tmpl-build-release.yml in build-manual.yml --- .github/workflows/build-manual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-manual.yml b/.github/workflows/build-manual.yml index c9c09c9..264cee6 100644 --- a/.github/workflows/build-manual.yml +++ b/.github/workflows/build-manual.yml @@ -20,7 +20,7 @@ on: jobs: call-tmpl-build-release: - uses: ./.github/workflows/tmpl-build-release.yml + uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml with: skippublish: ${{ inputs.skippublish }} skipghrelease: ${{ inputs.skipghrelease }} From a5b94dfb26ca41e841401b119e7eab56855904da Mon Sep 17 00:00:00 2001 From: Florian Hopfner <33372796+FH-Inway@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:48:08 +0000 Subject: [PATCH 2/7] Add missing ref to reusable workflow reference --- .github/workflows/build-manual.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-manual.yml b/.github/workflows/build-manual.yml index 264cee6..25814be 100644 --- a/.github/workflows/build-manual.yml +++ b/.github/workflows/build-manual.yml @@ -20,7 +20,7 @@ on: jobs: call-tmpl-build-release: - uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml + uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main with: skippublish: ${{ inputs.skippublish }} skipghrelease: ${{ inputs.skipghrelease }} From 0fe0fd1c5d595cc2952b9321d888ccbdc70fb0de Mon Sep 17 00:00:00 2001 From: Florian Hopfner Date: Sat, 4 May 2024 13:56:49 +0200 Subject: [PATCH 3/7] update to newest version of resusable build / release workflow --- .github/workflows/build-manual.yml | 14 ++++-- .github/workflows/build.yml | 5 +- .github/workflows/tmpl-build-release.yml | 63 ------------------------ 3 files changed, 11 insertions(+), 71 deletions(-) delete mode 100644 .github/workflows/tmpl-build-release.yml diff --git a/.github/workflows/build-manual.yml b/.github/workflows/build-manual.yml index 25814be..ee8c38c 100644 --- a/.github/workflows/build-manual.yml +++ b/.github/workflows/build-manual.yml @@ -11,18 +11,22 @@ on: - $True skipghrelease: description: "Determines if creation of a GitHub release is skipped" - default: $False + default: false required: false - type: choice - options: - - $False - - $True + type: boolean + skipValidation: + description: "Determines if the module validation is skipped" + default: false + required: false + type: boolean jobs: call-tmpl-build-release: uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main with: + module: 'd365bap.tools' skippublish: ${{ inputs.skippublish }} skipghrelease: ${{ inputs.skipghrelease }} + skipValidation: ${{ inputs.skipValidation }} secrets: apikey: ${{ secrets.ApiKey }} \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7b73477..05f6030 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,9 +6,8 @@ jobs: call-tmpl-build-release: - uses: ./.github/workflows/tmpl-build-release.yml + uses: fh-inway/d365.psmodule-alm/.github/workflows/tmpl-build-release.yml@main with: - skippublish: $False - skipghrelease: $False + module: 'd365bap.tools' secrets: apikey: ${{ secrets.ApiKey }} \ No newline at end of file diff --git a/.github/workflows/tmpl-build-release.yml b/.github/workflows/tmpl-build-release.yml deleted file mode 100644 index 336c18a..0000000 --- a/.github/workflows/tmpl-build-release.yml +++ /dev/null @@ -1,63 +0,0 @@ -# Template for a reusable workflow to build and release a PowerShell module. -# The template expects the following PowerShell scripts in the build folder of the repository root -# that do the actual validated build and release: -# - vsts-prerequisities.ps1 -# - vsts-validate.ps1 -# - vsts-build.ps1 - -on: - workflow_call: - inputs: - autoversion: - description: "Determines if the module's build version number is automatically incremented" - default: $True - required: false - type: string - skippublish: - description: "Determines if the publishing to the PowerShell Gallery is skipped" - default: $False - required: false - type: string - skipghrelease: - description: "Determines if a GitHub release is created" - default: $False - required: false - type: string - secrets: - apikey: - description: "Key for the PowerShell Gallery API" - required: true - -jobs: - build-and-release: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v1 - - name: Install Prerequisites - run: .\build\vsts-prerequisites.ps1 - shell: powershell - - name: Validate - run: .\build\vsts-validate.ps1 - shell: powershell - - name: Build - run: .\build\vsts-build.ps1 -ApiKey ${{ secrets.apikey }} -AutoVersion:${{ inputs.autoversion }} -SkipPublish:${{ inputs.skippublish }} - shell: powershell - - - name: Get version - run: | - $publishDir = Get-Item -Path publish - [version]$version = (Import-PowerShellDataFile -Path "$($publishDir.FullName)\d365bap.tools\d365bap.tools.psd1").ModuleVersion - $githubReleaseVersion = "$($version.Major).$($version.Minor).$($version.Build)" - "VERSION=$githubReleaseVersion" >> $env:GITHUB_ENV - shell: powershell - - - name: Create GitHub release - uses: softprops/action-gh-release@v2 - with: - name: ${{ env.VERSION }} - tag_name: ${{ env.VERSION }} - draft: false - prerelease: true - generate_release_notes: true \ No newline at end of file From d00502420c0ac52694214d843d6e1bccbdd40859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6tz=20Jensen?= Date: Tue, 18 Jun 2024 15:05:55 +0200 Subject: [PATCH 4/7] Feature: Support linking of Enterprise Policy between Dataverse and Azure Used for Synapse Link - with Managed Identity --- d365bap.tools/d365bap.tools.psd1 | 2 + .../functions/Get-BapEnvironment.ps1 | 2 + .../Get-BapEnvironmentSecurityRole.ps1 | 115 +++++++++++++++++ .../Invoke-BapEnvironmentInstallD365App.ps1 | 44 ++++++- ...Set-BapEnvironmentLinkEnterprisePolicy.ps1 | 70 ++++++++++ .../Get-BapEnvironmentSecurityRole.Tests.ps1 | 62 +++++++++ ...pEnvironmentLinkEnterprisePolicy.Tests.ps1 | 49 +++++++ d365bap.tools/xml/d365bap.tools.Format.ps1xml | 34 +++++ docs/Get-BapEnvironment.md | 2 + docs/Get-BapEnvironmentSecurityRole.md | 122 ++++++++++++++++++ docs/Get-BapEnvironmentSolution.md | 1 + docs/Invoke-BapEnvironmentInstallD365App.md | 29 +++++ .../Set-BapEnvironmentLinkEnterprisePolicy.md | 78 +++++++++++ 13 files changed, 608 insertions(+), 2 deletions(-) create mode 100644 d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 create mode 100644 d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 create mode 100644 d365bap.tools/tests/functions/Get-BapEnvironmentSecurityRole.Tests.ps1 create mode 100644 d365bap.tools/tests/functions/Set-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 create mode 100644 docs/Get-BapEnvironmentSecurityRole.md create mode 100644 docs/Set-BapEnvironmentLinkEnterprisePolicy.md diff --git a/d365bap.tools/d365bap.tools.psd1 b/d365bap.tools/d365bap.tools.psd1 index 53cd879..2930368 100644 --- a/d365bap.tools/d365bap.tools.psd1 +++ b/d365bap.tools/d365bap.tools.psd1 @@ -55,6 +55,7 @@ , 'Get-BapEnvironmentD365App' + , 'Get-BapEnvironmentSecurityRole' , 'Get-BapEnvironmentSolution' , 'Get-BapEnvironmentUser' @@ -63,6 +64,7 @@ , 'Invoke-BapEnvironmentInstallD365App' + , 'Set-BapEnvironmentLinkEnterprisePolicy' , 'Set-BapEnvironmentVirtualEntity' , 'Update-BapEnvironmentVirtualEntityMetadata' diff --git a/d365bap.tools/functions/Get-BapEnvironment.ps1 b/d365bap.tools/functions/Get-BapEnvironment.ps1 index 4ddaece..3b6527c 100644 --- a/d365bap.tools/functions/Get-BapEnvironment.ps1 +++ b/d365bap.tools/functions/Get-BapEnvironment.ps1 @@ -11,6 +11,8 @@ .PARAMETER EnvironmentId The id of the environment that you want to work against + Default value is "*" - which translates into all available environments + .PARAMETER AsExcelOutput Instruct the cmdlet to output all details directly to an Excel file diff --git a/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 b/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 new file mode 100644 index 0000000..1cd3aa2 --- /dev/null +++ b/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 @@ -0,0 +1,115 @@ + +<# + .SYNOPSIS + Get Security Roles from environment + + .DESCRIPTION + Get Security Roles from the Dataverse environment + + .PARAMETER EnvironmentId + The id of the environment that you want to work against + + .PARAMETER Name + Name of the Security Role that you want to work against + + Supports wildcard search + + Default value is "*" - which translates into all available Security Roles + + .PARAMETER AsExcelOutput + Instruct the cmdlet to output all details directly to an Excel file + + This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state + + .EXAMPLE + PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 + + This will list all Security Roles from the Dataverse environment. + + Sample output: + Id Name ModifiedOn + -- ---- ---------- + 5a8c8098-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.13 + 1cbf96a1-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.14 + d364ba1c-1bfb-eb11-94f0-0022482381ee Accounts Payable Admin 17/08/2023 07.06.15 + + .EXAMPLE + PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -Name "Environment*" + + This will list all Security Roles, which matches the "Environment*" pattern, from the Dataverse environment. + + Sample output: + Id Name ModifiedOn + -- ---- ---------- + d58407f2-48d5-e711-a82c-000d3a37c848 Environment Maker 15/06/2024 21.12.56 + + .EXAMPLE + PS C:\> Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput + + This will list all Security Roles from the Dataverse environment. + Will output all details into an Excel file, that will auto open on your machine. + + .NOTES + General notes +#> +function Get-BapEnvironmentSecurityRole { + [CmdletBinding()] + param ( + [parameter (mandatory = $true)] + [string] $EnvironmentId, + + [string] $Name = "*", + + [switch] $AsExcelOutput + ) + + begin { + # Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything. + $envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1 + + if ($null -eq $envObj) { + $messageString = "The supplied EnvironmentId: $EnvironmentId didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the Get-BapEnvironment cmdlet." + Write-PSFMessage -Level Host -Message $messageString + Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', ''))) + } + + if (Test-PSFFunctionInterrupt) { return } + + $baseUri = $envObj.LinkedMetaPpacEnvUri + $tokenWebApi = Get-AzAccessToken -ResourceUrl $baseUri + $headersWebApi = @{ + "Authorization" = "Bearer $($tokenWebApi.Token)" + } + + $languages = @(Get-EnvironmentLanguage -BaseUri $baseUri) + } + + process { + if (Test-PSFFunctionInterrupt) { return } + + $resRoles = Invoke-RestMethod -Method Get -Uri $($baseUri + '/api/data/v9.2/roles') -Headers $headersWebApi + + $resCol = @( + foreach ($roleObj in $($resRoles.value | Sort-Object -Property name)) { + if (-not ($roleObj.Name -like $Name)) { continue } + + $roleObj | Select-PSFObject -TypeName "D365Bap.Tools.Role" -ExcludeProperty "@odata.etag" -Property "roleid as Id", * + } + ) + + if (-not $IncludeAppIds) { + $resCol = $resCol | Where-Object applicationid -eq $null + } + + if ($AsExcelOutput) { + $resCol | Export-Excel + return + } + + $resCol + } + + end { + + } +} \ No newline at end of file diff --git a/d365bap.tools/functions/Invoke-BapEnvironmentInstallD365App.ps1 b/d365bap.tools/functions/Invoke-BapEnvironmentInstallD365App.ps1 index 3e63a57..58bdfc8 100644 --- a/d365bap.tools/functions/Invoke-BapEnvironmentInstallD365App.ps1 +++ b/d365bap.tools/functions/Invoke-BapEnvironmentInstallD365App.ps1 @@ -72,6 +72,32 @@ Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 Succeeded 02/03/2024 13.42.09 02/03/2024 13.48.26 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + .EXAMPLE + PS C:\> $apps = @(Get-BapEnvironmentD365App -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -InstallState Installed -UpdatesOnly) + PS C:\> Invoke-BapEnvironmentInstallD365App -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -PackageId $apps.PackageId + + This will find all D365 Apps that has a pending update available. + It will gather the Ids into an array. + It will run the cmdlet and have it get the status of the installation progress until all D365 Apps have been fully installed. + + Sample output (Install initialized): + status createdDateTime lastActionDateTime error statusMessage operationId + ------ --------------- ------------------ ----- ------------- ----------- + Running 02/03/2024 13.42.07 02/03/2024 13.42.16 5c80df7f-d89e-42bd-abeb-98e577ae49f4 + Running 02/03/2024 13.42.09 02/03/2024 13.42.12 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + + Sample output (Partly succeeded installation): + status createdDateTime lastActionDateTime error statusMessage operationId + ------ --------------- ------------------ ----- ------------- ----------- + Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 + Running 02/03/2024 13.42.09 02/03/2024 13.45.55 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + + Sample output (Completely succeeded installation): + status createdDateTime lastActionDateTime error statusMessage operationId + ------ --------------- ------------------ ----- ------------- ----------- + Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 + Succeeded 02/03/2024 13.42.09 02/03/2024 13.48.26 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + .NOTES Author: Mötz Jensen (@Splaxi) #> @@ -111,6 +137,7 @@ function Invoke-BapEnvironmentInstallD365App { [System.Collections.Generic.List[System.Object]] $arrInstallStarted = @() [System.Collections.Generic.List[System.Object]] $arrStatus = @() + [System.Collections.Generic.List[System.Object]] $arrFailedStarts = @() $headersPowerApi."Content-Type" = "application/json;charset=utf-8" @@ -124,11 +151,24 @@ function Invoke-BapEnvironmentInstallD365App { } $body = $appToBeInstalled | ConvertTo-Json - $resIntall = Invoke-RestMethod -Method Post -Uri "https://api.powerplatform.com/appmanagement/environments/$EnvironmentId/applicationPackages/$($appToBeInstalled.uniqueName)/install?api-version=2022-03-01-preview" -Headers $headersPowerApi -Body $body - $arrInstallStarted.Add($resIntall) + try { + $resIntall = Invoke-RestMethod -Method Post -Uri "https://api.powerplatform.com/appmanagement/environments/$EnvironmentId/applicationPackages/$($appToBeInstalled.uniqueName)/install?api-version=2022-03-01-preview" -Headers $headersPowerApi -Body $body + + $arrInstallStarted.Add($resIntall) + } + catch { + $arrFailedStarts.Add($appToBeInstalled) + } } + if ($arrFailedStarts.Count -gt 0) { + $messageString = "The following packages failed to start:" + Write-PSFMessage -Level Host -Message $messageString + + $arrFailedStarts.ToArray() + } + do { $tokenPowerApi = Get-AzAccessToken -ResourceUrl "https://api.powerplatform.com/" $headersPowerApi = @{ diff --git a/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 b/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 new file mode 100644 index 0000000..5dd5137 --- /dev/null +++ b/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 @@ -0,0 +1,70 @@ + +<# + .SYNOPSIS + Set the link between Dataverse and the Enterprise Policy + + .DESCRIPTION + To enable managed identity between Dataverse and Azure resources, you will need to work with the Enterprise Policy concept + + It needs to be linked, based on the SystemId of the Enterprise Policy (Azure) and the Dataverse environment (Id) + + .PARAMETER EnvironmentId + The id of the environment that you want to work against + + .PARAMETER EnterprisePolicyResourceId + The (system) id of the Enterprise Policy that you want to link to your Dataverse environment + + .EXAMPLE + PS C:\> Set-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -EnterprisePolicyResourceId '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatform/enterprisePolicies/EnterprisePolicy-Dataverse' + + This will link the Dataverse Environment to the Enterprise Policy. + The Environment is 'eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6'. + The EnterprisePolicy is '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatform/enterprisePolicies/EnterprisePolicy-Dataverse' + + .NOTES + Author: Mötz Jensen (@Splaxi) +#> +function Set-BapEnvironmentLinkEnterprisePolicy { + [CmdletBinding()] + param ( + [parameter (mandatory = $true)] + [string] $EnvironmentId, + + [parameter (mandatory = $true)] + [Alias('SystemId')] + [string] $EnterprisePolicyResourceId + ) + + begin { + # Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything. + $envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1 + + if ($null -eq $envObj) { + $messageString = "The supplied EnvironmentId: $EnvironmentId didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the Get-BapEnvironment cmdlet." + Write-PSFMessage -Level Host -Message $messageString + Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', ''))) + } + + if (Test-PSFFunctionInterrupt) { return } + + $tokenBap = Get-AzAccessToken -ResourceUrl "https://service.powerapps.com/" + $headers = @{ + "Authorization" = "Bearer $($tokenBap.Token)" + } + } + + process { + $body = [PsCustomObject]@{ + "SystemId" = $EnterprisePolicyResourceId + } | ConvertTo-Json + + # 2019-10-01 + $uriLinkEnterprisePolicy = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/$EnvironmentId/enterprisePolicies/Identity/link?api-version=2023-06-01" + + Invoke-RestMethod -Method Post -Uri $uriLinkEnterprisePolicy -Headers $headers -Body $body -ContentType "application/json" > $null + } + + end { + + } +} \ No newline at end of file diff --git a/d365bap.tools/tests/functions/Get-BapEnvironmentSecurityRole.Tests.ps1 b/d365bap.tools/tests/functions/Get-BapEnvironmentSecurityRole.Tests.ps1 new file mode 100644 index 0000000..adccc3d --- /dev/null +++ b/d365bap.tools/tests/functions/Get-BapEnvironmentSecurityRole.Tests.ps1 @@ -0,0 +1,62 @@ +Describe "Get-BapEnvironmentSecurityRole Unit Tests" -Tag "Unit" { + BeforeAll { + # Place here all things needed to prepare for the tests + } + AfterAll { + # Here is where all the cleanup tasks go + } + + Describe "Ensuring unchanged command signature" { + It "should have the expected parameter sets" { + (Get-Command Get-BapEnvironmentSecurityRole).ParameterSets.Name | Should -Be '__AllParameterSets' + } + + It 'Should have the expected parameter EnvironmentId' { + $parameter = (Get-Command Get-BapEnvironmentSecurityRole).Parameters['EnvironmentId'] + $parameter.Name | Should -Be 'EnvironmentId' + $parameter.ParameterType.ToString() | Should -Be System.String + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 0 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + It 'Should have the expected parameter Name' { + $parameter = (Get-Command Get-BapEnvironmentSecurityRole).Parameters['Name'] + $parameter.Name | Should -Be 'Name' + $parameter.ParameterType.ToString() | Should -Be System.String + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 1 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + It 'Should have the expected parameter AsExcelOutput' { + $parameter = (Get-Command Get-BapEnvironmentSecurityRole).Parameters['AsExcelOutput'] + $parameter.Name | Should -Be 'AsExcelOutput' + $parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be -2147483648 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + } + + Describe "Testing parameterset __AllParameterSets" { + <# + __AllParameterSets -EnvironmentId + __AllParameterSets -EnvironmentId -Name -AsExcelOutput + #> + } + +} \ No newline at end of file diff --git a/d365bap.tools/tests/functions/Set-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 b/d365bap.tools/tests/functions/Set-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 new file mode 100644 index 0000000..b010cdc --- /dev/null +++ b/d365bap.tools/tests/functions/Set-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 @@ -0,0 +1,49 @@ +Describe "Set-BapEnvironmentLinkEnterprisePolicy Unit Tests" -Tag "Unit" { + BeforeAll { + # Place here all things needed to prepare for the tests + } + AfterAll { + # Here is where all the cleanup tasks go + } + + Describe "Ensuring unchanged command signature" { + It "should have the expected parameter sets" { + (Get-Command Set-BapEnvironmentLinkEnterprisePolicy).ParameterSets.Name | Should -Be '__AllParameterSets' + } + + It 'Should have the expected parameter EnvironmentId' { + $parameter = (Get-Command Set-BapEnvironmentLinkEnterprisePolicy).Parameters['EnvironmentId'] + $parameter.Name | Should -Be 'EnvironmentId' + $parameter.ParameterType.ToString() | Should -Be System.String + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 0 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + It 'Should have the expected parameter EnterprisePolicyResourceId' { + $parameter = (Get-Command Set-BapEnvironmentLinkEnterprisePolicy).Parameters['EnterprisePolicyResourceId'] + $parameter.Name | Should -Be 'EnterprisePolicyResourceId' + $parameter.ParameterType.ToString() | Should -Be System.String + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 1 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + } + + Describe "Testing parameterset __AllParameterSets" { + <# + __AllParameterSets -EnvironmentId -EnterprisePolicyResourceId + __AllParameterSets -EnvironmentId -EnterprisePolicyResourceId + #> + } + +} \ No newline at end of file diff --git a/d365bap.tools/xml/d365bap.tools.Format.ps1xml b/d365bap.tools/xml/d365bap.tools.Format.ps1xml index 4212e66..0bfec7f 100644 --- a/d365bap.tools/xml/d365bap.tools.Format.ps1xml +++ b/d365bap.tools/xml/d365bap.tools.Format.ps1xml @@ -481,5 +481,39 @@ + + D365Bap.Tools.Role + + D365Bap.Tools.Role + + + + + 36 + + + 30 + + + 30 + + + + + + + Id + + + Name + + + ModifiedOn + + + + + + \ No newline at end of file diff --git a/docs/Get-BapEnvironment.md b/docs/Get-BapEnvironment.md index 8e4ee3e..27d8915 100644 --- a/docs/Get-BapEnvironment.md +++ b/docs/Get-BapEnvironment.md @@ -63,6 +63,8 @@ Will output all details into an Excel file, that will auto open on your machine. ### -EnvironmentId The id of the environment that you want to work against +Default value is "*" - which translates into all available environments + ```yaml Type: String Parameter Sets: (All) diff --git a/docs/Get-BapEnvironmentSecurityRole.md b/docs/Get-BapEnvironmentSecurityRole.md new file mode 100644 index 0000000..d6e9829 --- /dev/null +++ b/docs/Get-BapEnvironmentSecurityRole.md @@ -0,0 +1,122 @@ +--- +external help file: d365bap.tools-help.xml +Module Name: d365bap.tools +online version: +schema: 2.0.0 +--- + +# Get-BapEnvironmentSecurityRole + +## SYNOPSIS +Get Security Roles from environment + +## SYNTAX + +``` +Get-BapEnvironmentSecurityRole [-EnvironmentId] [[-Name] ] [-AsExcelOutput] + [] +``` + +## DESCRIPTION +Get Security Roles from the Dataverse environment + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 +``` + +This will list all Security Roles from the Dataverse environment. + +Sample output: +Id Name ModifiedOn +-- ---- ---------- +5a8c8098-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.13 +1cbf96a1-b933-eb11-a813-000d3a8e7ded (Deprecated) Marketing Realti… 03/02/2023 10.11.14 +d364ba1c-1bfb-eb11-94f0-0022482381ee Accounts Payable Admin 17/08/2023 07.06.15 + +### EXAMPLE 2 +``` +Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -Name "Environment*" +``` + +This will list all Security Roles, which matches the "Environment*" pattern, from the Dataverse environment. + +Sample output: +Id Name ModifiedOn +-- ---- ---------- +d58407f2-48d5-e711-a82c-000d3a37c848 Environment Maker 15/06/2024 21.12.56 + +### EXAMPLE 3 +``` +Get-BapEnvironmentSecurityRole -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput +``` + +This will list all Security Roles from the Dataverse environment. +Will output all details into an Excel file, that will auto open on your machine. + +## PARAMETERS + +### -EnvironmentId +The id of the environment that you want to work against + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Name of the Security Role that you want to work against + +Supports wildcard search + +Default value is "*" - which translates into all available Security Roles + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsExcelOutput +Instruct the cmdlet to output all details directly to an Excel file + +This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +General notes + +## RELATED LINKS diff --git a/docs/Get-BapEnvironmentSolution.md b/docs/Get-BapEnvironmentSolution.md index b58549f..98a1e32 100644 --- a/docs/Get-BapEnvironmentSolution.md +++ b/docs/Get-BapEnvironmentSolution.md @@ -171,6 +171,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable ## OUTPUTS +### System.Object[] ## NOTES Author: Mötz Jensen (@Splaxi) diff --git a/docs/Invoke-BapEnvironmentInstallD365App.md b/docs/Invoke-BapEnvironmentInstallD365App.md index a81f781..c9905e5 100644 --- a/docs/Invoke-BapEnvironmentInstallD365App.md +++ b/docs/Invoke-BapEnvironmentInstallD365App.md @@ -80,6 +80,35 @@ status createdDateTime lastActionDateTime error statusMessage operationI Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 Succeeded 02/03/2024 13.42.09 02/03/2024 13.48.26 6885e0f4-639f-4ebc-b21e-49ce5d5e920d +### EXAMPLE 3 +``` +$apps = @(Get-BapEnvironmentD365App -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -InstallState Installed -UpdatesOnly) +``` + +PS C:\\\> Invoke-BapEnvironmentInstallD365App -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -PackageId $apps.PackageId + +This will find all D365 Apps that has a pending update available. +It will gather the Ids into an array. +It will run the cmdlet and have it get the status of the installation progress until all D365 Apps have been fully installed. + +Sample output (Install initialized): +status createdDateTime lastActionDateTime error statusMessage operationId +------ --------------- ------------------ ----- ------------- ----------- +Running 02/03/2024 13.42.07 02/03/2024 13.42.16 5c80df7f-d89e-42bd-abeb-98e577ae49f4 +Running 02/03/2024 13.42.09 02/03/2024 13.42.12 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + +Sample output (Partly succeeded installation): +status createdDateTime lastActionDateTime error statusMessage operationId +------ --------------- ------------------ ----- ------------- ----------- +Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 +Running 02/03/2024 13.42.09 02/03/2024 13.45.55 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + +Sample output (Completely succeeded installation): +status createdDateTime lastActionDateTime error statusMessage operationId +------ --------------- ------------------ ----- ------------- ----------- +Succeeded 02/03/2024 13.42.07 02/03/2024 13.44.48 5c80df7f-d89e-42bd-abeb-98e577ae49f4 +Succeeded 02/03/2024 13.42.09 02/03/2024 13.48.26 6885e0f4-639f-4ebc-b21e-49ce5d5e920d + ## PARAMETERS ### -EnvironmentId diff --git a/docs/Set-BapEnvironmentLinkEnterprisePolicy.md b/docs/Set-BapEnvironmentLinkEnterprisePolicy.md new file mode 100644 index 0000000..1439637 --- /dev/null +++ b/docs/Set-BapEnvironmentLinkEnterprisePolicy.md @@ -0,0 +1,78 @@ +--- +external help file: d365bap.tools-help.xml +Module Name: d365bap.tools +online version: +schema: 2.0.0 +--- + +# Set-BapEnvironmentLinkEnterprisePolicy + +## SYNOPSIS +Set the link between Dataverse and the Enterprise Policy + +## SYNTAX + +``` +Set-BapEnvironmentLinkEnterprisePolicy [-EnvironmentId] [-EnterprisePolicyResourceId] + [] +``` + +## DESCRIPTION +To enable managed identity between Dataverse and Azure resources, you will need to work with the Enterprise Policy concept + +It needs to be linked, based on the SystemId of the Enterprise Policy (Azure) and the Dataverse environment (Id) + +## EXAMPLES + +### EXAMPLE 1 +``` +Set-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -EnterprisePolicyResourceId '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatform/enterprisePolicies/EnterprisePolicy-Dataverse' +``` + +This will link the Dataverse Environment to the Enterprise Policy. +The Environment is 'eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6'. +The EnterprisePolicy is '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatform/enterprisePolicies/EnterprisePolicy-Dataverse' + +## PARAMETERS + +### -EnvironmentId +The id of the environment that you want to work against + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -EnterprisePolicyResourceId +The (system) id of the Enterprise Policy that you want to link to your Dataverse environment + +```yaml +Type: String +Parameter Sets: (All) +Aliases: SystemId + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +Author: Mötz Jensen (@Splaxi) + +## RELATED LINKS From 8a61a9601aebd9ccf6078c5ad7ef67ea8da5d051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6tz=20Jensen?= Date: Wed, 19 Jun 2024 15:44:20 +0200 Subject: [PATCH 5/7] Test: Fixing unit tests --- d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 | 2 -- .../functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 b/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 index 1cd3aa2..3442df7 100644 --- a/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 +++ b/d365bap.tools/functions/Get-BapEnvironmentSecurityRole.ps1 @@ -80,8 +80,6 @@ function Get-BapEnvironmentSecurityRole { $headersWebApi = @{ "Authorization" = "Bearer $($tokenWebApi.Token)" } - - $languages = @(Get-EnvironmentLanguage -BaseUri $baseUri) } process { diff --git a/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 b/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 index 5dd5137..fe66270 100644 --- a/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 +++ b/d365bap.tools/functions/Set-BapEnvironmentLinkEnterprisePolicy.ps1 @@ -25,6 +25,7 @@ Author: Mötz Jensen (@Splaxi) #> function Set-BapEnvironmentLinkEnterprisePolicy { + [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")] [CmdletBinding()] param ( [parameter (mandatory = $true)] From 85ff98180bf12acdee029f6fcd25816d74c5ba6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6tz=20Jensen?= Date: Wed, 19 Jun 2024 16:13:14 +0200 Subject: [PATCH 6/7] Feature: Add Get-BapEnvironmentLinkEnterprisePolicy --- d365bap.tools/d365bap.tools.psd1 | 2 + ...Get-BapEnvironmentLinkEnterprisePolicy.ps1 | 108 ++++++++++++++++++ ...pEnvironmentLinkEnterprisePolicy.Tests.ps1 | 49 ++++++++ .../Get-BapEnvironmentLinkEnterprisePolicy.md | 94 +++++++++++++++ 4 files changed, 253 insertions(+) create mode 100644 d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 create mode 100644 d365bap.tools/tests/functions/Get-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 create mode 100644 docs/Get-BapEnvironmentLinkEnterprisePolicy.md diff --git a/d365bap.tools/d365bap.tools.psd1 b/d365bap.tools/d365bap.tools.psd1 index 2930368..4a0e218 100644 --- a/d365bap.tools/d365bap.tools.psd1 +++ b/d365bap.tools/d365bap.tools.psd1 @@ -54,6 +54,8 @@ , 'Get-BapEnvironmentApplicationUser' , 'Get-BapEnvironmentD365App' + + , 'Get-BapEnvironmentLinkEnterprisePolicy' , 'Get-BapEnvironmentSecurityRole' , 'Get-BapEnvironmentSolution' diff --git a/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 b/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 new file mode 100644 index 0000000..f941240 --- /dev/null +++ b/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 @@ -0,0 +1,108 @@ + +<# + .SYNOPSIS + Get Enterprise Policy + + .DESCRIPTION + Get all registered Enterprise Policies from a Dataverse environment and its linked status + + .PARAMETER EnvironmentId + The id of the environment that you want to work against + + .PARAMETER AsExcelOutput + Instruct the cmdlet to output all details directly to an Excel file + + This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state + + .EXAMPLE + PS C:\> Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 + + This will get all Enterprise Policy informations from the Dataverse environment. + + Sample output: + PpacEnvId : eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 + PpacEnvName : new-test + Type : identity + policyId : d3e06308-e287-42bb-ad6d-a588ef77d6e8 + location : europe + id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatfor + m/enterprisePolicies/EnterprisePolicy-Dataverse + systemId : /regions/europe/providers/Microsoft.PowerPlatform/enterprisePolicies/d3e06308-e287-42bb-ad6d-a588ef77d6e8 + linkStatus : Linked + + .EXAMPLE + PS C:\> Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput + + This will get all Enterprise Policy informations from the Dataverse environment. + Will output all details into an Excel file, that will auto open on your machine. + + .NOTES + Author: Mötz Jensen (@Splaxi) +#> +function Get-BapEnvironmentLinkEnterprisePolicy { + [CmdletBinding()] + param ( + [parameter (mandatory = $true)] + [string] $EnvironmentId, + + [switch] $AsExcelOutput + ) + + begin { + # Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything. + $envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1 + + if ($null -eq $envObj) { + $messageString = "The supplied EnvironmentId: $EnvironmentId didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the Get-BapEnvironment cmdlet." + Write-PSFMessage -Level Host -Message $messageString + Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', ''))) + } + + if (Test-PSFFunctionInterrupt) { return } + + $tokenBap = Get-AzAccessToken -ResourceUrl "https://service.powerapps.com/" + $headers = @{ + "Authorization" = "Bearer $($tokenBap.Token)" + } + } + + process { + $body = [PsCustomObject]@{ + "SystemId" = $EnterprisePolicyResourceId + } | ConvertTo-Json + + # 2019-10-01 + $uriLinkEnterprisePolicy = "https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/$EnvironmentId`?api-version=2024-05-01" + + $resObj = Invoke-RestMethod -Method Get -Uri $uriLinkEnterprisePolicy -Headers $headers -Body $body -ContentType "application/json" + + $resCol = @( + if ($null -ne $resObj.properties.enterprisePolicies) { + foreach ($prop in $resObj.properties.enterprisePolicies.psobject.Properties) { + $enterprisePolicyObj = [ordered]@{ + PpacEnvId = $envObj.PpacEnvId + PpacEnvName = $envObj.PpacEnvName + Type = $prop.Name + } + + foreach ($innerProp in $prop.Value.psobject.properties) { + $enterprisePolicyObj."$($innerProp.Name)" = $innerProp.Value + } + + ([PSCustomObject]$enterprisePolicyObj) | Select-PSFObject -TypeName "D365Bap.Tools.Environment.EnterprisePolicy" + } + } + ) + + if ($AsExcelOutput) { + $resCol | Export-Excel + return + } + + $resCol + } + + end { + + } +} \ No newline at end of file diff --git a/d365bap.tools/tests/functions/Get-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 b/d365bap.tools/tests/functions/Get-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 new file mode 100644 index 0000000..8226938 --- /dev/null +++ b/d365bap.tools/tests/functions/Get-BapEnvironmentLinkEnterprisePolicy.Tests.ps1 @@ -0,0 +1,49 @@ +Describe "Get-BapEnvironmentLinkEnterprisePolicy Unit Tests" -Tag "Unit" { + BeforeAll { + # Place here all things needed to prepare for the tests + } + AfterAll { + # Here is where all the cleanup tasks go + } + + Describe "Ensuring unchanged command signature" { + It "should have the expected parameter sets" { + (Get-Command Get-BapEnvironmentLinkEnterprisePolicy).ParameterSets.Name | Should -Be '__AllParameterSets' + } + + It 'Should have the expected parameter EnvironmentId' { + $parameter = (Get-Command Get-BapEnvironmentLinkEnterprisePolicy).Parameters['EnvironmentId'] + $parameter.Name | Should -Be 'EnvironmentId' + $parameter.ParameterType.ToString() | Should -Be System.String + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $True + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be 0 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + It 'Should have the expected parameter AsExcelOutput' { + $parameter = (Get-Command Get-BapEnvironmentLinkEnterprisePolicy).Parameters['AsExcelOutput'] + $parameter.Name | Should -Be 'AsExcelOutput' + $parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter + $parameter.IsDynamic | Should -Be $False + $parameter.ParameterSets.Keys | Should -Be '__AllParameterSets' + $parameter.ParameterSets.Keys | Should -Contain '__AllParameterSets' + $parameter.ParameterSets['__AllParameterSets'].IsMandatory | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].Position | Should -Be -2147483648 + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipeline | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromPipelineByPropertyName | Should -Be $False + $parameter.ParameterSets['__AllParameterSets'].ValueFromRemainingArguments | Should -Be $False + } + } + + Describe "Testing parameterset __AllParameterSets" { + <# + __AllParameterSets -EnvironmentId + __AllParameterSets -EnvironmentId -AsExcelOutput + #> + } + +} \ No newline at end of file diff --git a/docs/Get-BapEnvironmentLinkEnterprisePolicy.md b/docs/Get-BapEnvironmentLinkEnterprisePolicy.md new file mode 100644 index 0000000..b90f81a --- /dev/null +++ b/docs/Get-BapEnvironmentLinkEnterprisePolicy.md @@ -0,0 +1,94 @@ +--- +external help file: d365bap.tools-help.xml +Module Name: d365bap.tools +online version: +schema: 2.0.0 +--- + +# Get-BapEnvironmentLinkEnterprisePolicy + +## SYNOPSIS +Get Enterprise Policy + +## SYNTAX + +``` +Get-BapEnvironmentLinkEnterprisePolicy [-EnvironmentId] [-AsExcelOutput] [] +``` + +## DESCRIPTION +Get all registered Enterprise Policies from a Dataverse environment and its linked status + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 +``` + +This will get all Enterprise Policy informations from the Dataverse environment. + +Sample output: +PpacEnvId : eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 +PpacEnvName : new-test +Type : identity +policyId : d3e06308-e287-42bb-ad6d-a588ef77d6e8 +location : europe +id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-01/providers/Microsoft.PowerPlatfor +m/enterprisePolicies/EnterprisePolicy-Dataverse +systemId : /regions/europe/providers/Microsoft.PowerPlatform/enterprisePolicies/d3e06308-e287-42bb-ad6d-a588ef77d6e8 +linkStatus : Linked + +### EXAMPLE 2 +``` +Get-BapEnvironmentLinkEnterprisePolicy -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -AsExcelOutput +``` + +This will get all Enterprise Policy informations from the Dataverse environment. +Will output all details into an Excel file, that will auto open on your machine. + +## PARAMETERS + +### -EnvironmentId +The id of the environment that you want to work against + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -AsExcelOutput +Instruct the cmdlet to output all details directly to an Excel file + +This makes it easier to deep dive into all the details returned from the API, and makes it possible for the user to persist the current state + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES +Author: Mötz Jensen (@Splaxi) + +## RELATED LINKS From edc34e4a3f07ae3468064919519782a0b7e6751c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6tz=20Jensen?= Date: Wed, 19 Jun 2024 16:20:36 +0200 Subject: [PATCH 7/7] Feature: Add Get-BapEnvironmentLinkEnterprisePolicy --- .../functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 b/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 index f941240..7823c6e 100644 --- a/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 +++ b/d365bap.tools/functions/Get-BapEnvironmentLinkEnterprisePolicy.ps1 @@ -41,6 +41,7 @@ #> function Get-BapEnvironmentLinkEnterprisePolicy { [CmdletBinding()] + [OutputType('System.Object[]')] param ( [parameter (mandatory = $true)] [string] $EnvironmentId,