├── images ├── Fabtools.ico ├── Fabtools.png ├── Fabtools50.png ├── FabricToolsLogo.ico └── FabricToolsLogo.png ├── source ├── FabricTools.psm1 ├── en-US │ └── about_FabricTools.help.txt ├── Public │ ├── Get-FabricDebugInfo.ps1 │ ├── Config │ │ ├── Get-FabricConfig.ps1 │ │ └── Set-FabricConfig.ps1 │ ├── Get-FabricAuthToken.ps1 │ ├── Capacity │ │ ├── Get-FabricCapacityTenantOverrides.ps1 │ │ ├── Get-FabricCapacityRefreshables.ps1 │ │ ├── Get-FabricCapacityWorkload.ps1 │ │ ├── Get-FabricCapacitySkus.ps1 │ │ ├── Get-FabricCapacityState.ps1 │ │ ├── Suspend-FabricCapacity.ps1 │ │ └── Resume-FabricCapacity.ps1 │ ├── Get-SHA256.ps1 │ ├── Get-FabricConnection.ps1 │ ├── Get-FabricAPIClusterURI.ps1 │ ├── Dashboard │ │ └── Get-FabricDashboard.ps1 │ ├── Invoke-FabricDatasetRefresh.ps1 │ ├── Utils │ │ ├── Convert-FromBase64.ps1 │ │ ├── Get-FabricLongRunningOperationResult.ps1 │ │ └── Convert-ToBase64.ps1 │ ├── External Data Share │ │ ├── Get-FabricExternalDataShares.ps1 │ │ └── Revoke-FabricExternalDataShares.ps1 │ ├── Deployment Pipeline │ │ ├── Get-FabricDeploymentPipelineRoleAssignments.ps1 │ │ ├── Remove-FabricDeploymentPipeline.ps1 │ │ ├── Get-FabricDeploymentPipelineOperation.ps1 │ │ └── Get-FabricDeploymentPipelineStageItem.ps1 │ ├── Workspace │ │ ├── Unregister-FabricWorkspaceToCapacity.ps1 │ │ ├── Get-FabricWorkspaceDatasetRefreshes.ps1 │ │ ├── New-FabricWorkspaceUsageMetricsReport.ps1 │ │ ├── Remove-FabricWorkspace.ps1 │ │ ├── Remove-FabricWorkspaceCapacityAssignment.ps1 │ │ └── Get-FabricWorkspaceUsageMetricsData.ps1 │ ├── Tenant │ │ ├── Get-FabricWorkspaceTenantSettingOverrides.ps1 │ │ └── Get-FabricDomainTenantSettingOverrides.ps1 │ ├── Domain │ │ ├── Remove-FabricDomain.ps1 │ │ └── Get-FabricDomainWorkspace.ps1 │ ├── Item │ │ └── Get-FabricItem.ps1 │ ├── Copy Job │ │ └── Remove-FabricCopyJob.ps1 │ ├── SQL Database │ │ └── Remove-FabricSQLDatabase.ps1 │ ├── Data Pipeline │ │ └── Remove-FabricDataPipeline.ps1 │ ├── Warehouse │ │ └── Remove-FabricWarehouse.ps1 │ ├── Notebook │ │ └── Remove-FabricNotebook.ps1 │ ├── Lakehouse │ │ └── Remove-FabricLakehouse.ps1 │ └── Environment │ │ └── Get-FabricEnvironmentLibrary.ps1 └── Private │ ├── Set-FabConfig.ps1 │ ├── Get-FabricContinuationToken.ps1 │ └── Get-FileDefinitionParts.ps1 ├── .markdownlint.json ├── .vscode ├── extensions.json ├── analyzersettings.psd1 └── settings.json ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── General.md │ ├── Resource_proposal.yml │ └── Problem_with_resource.yml ├── copilot-commit-message-instructions.md ├── workflows │ └── publish-module.yml └── PULL_REQUEST_TEMPLATE.md ├── .gitattributes ├── helper ├── build.ps1 ├── build-and-test.ps1 └── GetFunctionList.ps1 ├── .gitignore ├── tests └── Unit │ ├── Set-FabricConfig.tests.ps1 │ ├── New-FabricRecoveryPoint.tests.ps1 │ ├── Remove-FabricRecoveryPoint.tests.ps1 │ ├── Get-FabricRecoveryPoint.tests.ps1 │ ├── Get-FabricUri.tests.ps1 │ ├── Get-FabricAPIclusterURI.Tests.ps1 │ ├── Get-FabricAuthToken.Tests.ps1 │ ├── Get-FabricDebugInfo.Tests.ps1 │ ├── Import-FabricItem.Tests.ps1 │ ├── Convert-FromBase64.Tests.ps1 │ ├── Update-FabricCapacityTenantSettingOverrides.Tests.ps1 │ ├── Convert-ToBase64.Tests.ps1 │ ├── Connect-FabricAccount.Tests.ps1 │ ├── Get-Sha256.Tests.ps1 │ ├── Get-FabricContinuationToken.Tests.ps1 │ ├── Get-FabricConfig.tests.ps1 │ ├── Get-FabricWorkspaceTenantSettingOverrides.Tests.ps1 │ ├── Get-FabricExternalDataShares.Tests.ps1 │ ├── Get-FabricWorkspaceUsageMetricsData.Tests.ps1 │ ├── Get-FabricDashboard.Tests.ps1 │ ├── Invoke-FabricDatasetRefresh.Tests.ps1 │ ├── Update-FabricCopyJobDefinition.Tests.ps1 │ ├── Get-FabricWorkspaceDatasetRefreshes.Tests.ps1 │ ├── Get-FabricSparkSettings.Tests.ps1 │ ├── Get-FabricLongRunningOperationResult.Tests.ps1 │ ├── Get-FabricUserListAccessEntities.Tests.ps1 │ └── Import-FabricEnvironmentStagingLibrary.Tests.ps1 ├── .devcontainer ├── devcontainer.json └── post-create.ps1 ├── codecov.yml ├── GitVersion.yml ├── LICENSE ├── RequiredModules.psd1 ├── docs └── en-US │ ├── Get-FabricCapacityTenantOverrides.md │ ├── Get-FabricAuthToken.md │ ├── Get-Sha256.md │ ├── Get-FabricConfig.md │ ├── Get-FabricDebugInfo.md │ ├── Get-FabricExternalDataShares.md │ ├── Get-FabricAPIclusterURI.md │ ├── Get-FabricWorkspaceTenantSettingOverrides.md │ ├── Get-FabricDomainTenantSettingOverrides.md │ ├── Get-FabricDomainWorkspace.md │ ├── Add-FabricWorkspaceIdentity.md │ ├── Get-FabricConnection.md │ ├── Get-FabricDashboard.md │ ├── Get-FabricCapacityRefreshables.md │ ├── Get-FabricCapacityWorkload.md │ ├── Invoke-FabricDatasetRefresh.md │ ├── Convert-FromBase64.md │ ├── Get-FabricTenantSetting.md │ ├── Get-FabricSparkSettings.md │ ├── Get-FabricDeploymentPipelineRoleAssignments.md │ └── Get-FabricLongRunningOperationResult.md └── SECURITY.md /images/Fabtools.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataplat/FabricTools/HEAD/images/Fabtools.ico -------------------------------------------------------------------------------- /images/Fabtools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataplat/FabricTools/HEAD/images/Fabtools.png -------------------------------------------------------------------------------- /images/Fabtools50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataplat/FabricTools/HEAD/images/Fabtools50.png -------------------------------------------------------------------------------- /images/FabricToolsLogo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataplat/FabricTools/HEAD/images/FabricToolsLogo.ico -------------------------------------------------------------------------------- /images/FabricToolsLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dataplat/FabricTools/HEAD/images/FabricToolsLogo.png -------------------------------------------------------------------------------- /source/FabricTools.psm1: -------------------------------------------------------------------------------- 1 | <# 2 | This file is intentionally left empty. It is must be left here for the module 3 | manifest to refer to. It is recreated during the build process. 4 | #> 5 | 6 | -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "MD029": { 4 | "style": "one" 5 | }, 6 | "MD013": true, 7 | "MD024": false, 8 | "MD034": false, 9 | "no-hard-tabs": true 10 | } 11 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "davidanson.vscode-markdownlint", 4 | "ms-vscode.powershell", 5 | "streetsidesoftware.code-spell-checker", 6 | "redhat.vscode-yaml" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: "FabricTools Community" 4 | url: https://github.com/dataplat/FabricTools/discussions 5 | about: "To talk to the community and maintainers of FabricTools, please head to GitHub discussions." 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/General.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: General question or documentation update 3 | about: If you have a general question or documentation update suggestion around the resource module. 4 | --- 5 | 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Needed for publishing of examples, build worker defaults to core.autocrlf=input. 2 | * text eol=autocrlf 3 | 4 | *.mof text eol=crlf 5 | *.sh text eol=lf 6 | *.svg eol=lf 7 | 8 | # Ensure any exe files are treated as binary 9 | *.exe binary 10 | *.jpg binary 11 | *.xl* binary 12 | *.pfx binary 13 | *.png binary 14 | *.dll binary 15 | *.so binary 16 | -------------------------------------------------------------------------------- /helper/build.ps1: -------------------------------------------------------------------------------- 1 | Remove-Module -Name FabricTools -ErrorAction SilentlyContinue 2 | ./build.ps1 -Tasks build 3 | ipmo .\output\module\FabricTools\0.0.1\FabricTools.psd1 4 | Get-Module FabricTools 5 | 6 | Write-Host "Connecting to Fabric Account..." -ForegroundColor Cyan 7 | Connect-FabricAccount 8 | 9 | Write-Host "Build completed successfully!" -ForegroundColor Green 10 | -------------------------------------------------------------------------------- /.github/copilot-commit-message-instructions.md: -------------------------------------------------------------------------------- 1 | # Limit the subject line to 50 characters 2 | Capitalize the subject/description line 3 | Do not end the subject line with a period 4 | Separate the subject from the body with a blank line 5 | Use the imperative mood in the subject line 6 | The subject line should be a single sentence with an action word and a target with some reasoning for the change 7 | Use the body to explain what and why in a friendly kind manner 8 | Say thank you at the end of the message 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **.bak 2 | *.local.* 3 | !**/README.md 4 | .kitchen/ 5 | *.code-workspace 6 | 7 | ~*.* 8 | *.nupkg 9 | *.suo 10 | *.user 11 | *.userosscache 12 | *.sln.docstates 13 | 14 | # Build results 15 | [Oo]utput/ 16 | 17 | # MSTest test Results 18 | [Tt]est[Rr]esult*/ 19 | [Bb]uild[Ll]og.* 20 | 21 | # NUNIT 22 | *.VisualState.xml 23 | TestResult.xml 24 | 25 | # Visual Studio code coverage results 26 | *.coverage 27 | .vs 28 | .psproj 29 | .sln 30 | markdownissues.txt 31 | node_modules 32 | package-lock.json 33 | 34 | # just a comment 35 | -------------------------------------------------------------------------------- /tests/Unit/Set-FabricConfig.tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Set-FabricConfig Unit Tests" -Tag 'UnitTests' { 2 | Context "Validate parameters" { 3 | It "Should only contain our specific parameters" { 4 | $CommandName = 'Set-FabricConfig' 5 | [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys 6 | [object[]]$knownParameters = 'WorkspaceGUID','DataWarehouseGUID','BaseUrl','SkipPersist' 7 | Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/Unit/New-FabricRecoveryPoint.tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "New-FabricRecoveryPoint Unit Tests" -Tag 'UnitTests' { 2 | Context "Validate parameters" { 3 | It "Should only contain our specific parameters" { 4 | $CommandName = 'New-FabricRecoveryPoint' 5 | [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys 6 | [object[]]$knownParameters = 'WorkspaceGUID','DataWarehouseGUID','BaseUrl' 7 | Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /source/en-US/about_FabricTools.help.txt: -------------------------------------------------------------------------------- 1 | TOPIC 2 | about_FabricTools 3 | 4 | SHORT DESCRIPTION 5 | A module to be able to do more with Microsoft Fabric. 6 | 7 | LONG DESCRIPTION 8 | A module to be able to do more with Microsoft Fabric. 9 | 10 | EXAMPLES 11 | PS C:\> {{ add examples here }} 12 | 13 | NOTE: 14 | Thank you to all those who contributed to this module, by writing code, sharing opinions, and provided feedback. 15 | 16 | TROUBLESHOOTING NOTE: 17 | Look out on the Github repository for issues and new releases. 18 | 19 | SEE ALSO 20 | - {{ Please add Project URI such as github }}} 21 | 22 | KEYWORDS 23 | {{ Add comma separated keywords here }} 24 | 25 | -------------------------------------------------------------------------------- /tests/Unit/Remove-FabricRecoveryPoint.tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Remove-FabricRecoveryPoint Unit Tests" -Tag 'UnitTests' { 2 | Context "Validate parameters" { 3 | It "Should only contain our specific parameters" { 4 | $CommandName = 'Remove-FabricRecoveryPoint' 5 | [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys 6 | [object[]]$knownParameters = 'CreateTime','WorkspaceGUID','DataWarehouseGUID','BaseUrl' 7 | Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricRecoveryPoint.tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Get-FabricRecoveryPoint Unit Tests" -Tag 'UnitTests' { 2 | Context "Validate parameters" { 3 | It "Should only contain our specific parameters" { 4 | $CommandName = 'Get-FabricRecoveryPoint' 5 | [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys 6 | [object[]]$knownParameters = 'WorkspaceGUID','DataWarehouseGUID','BaseUrl','Since','Type','CreateTime' 7 | Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricUri.tests.ps1: -------------------------------------------------------------------------------- 1 | Describe "Get-FabricUri Unit Tests" -Tag 'UnitTests' -Skip { 2 | Context "Validate parameters" { 3 | It "Should only contain our specific parameters" { 4 | $CommandName = 'Get-FabricUri' 5 | [array]$params = ([Management.Automation.CommandMetaData]$ExecutionContext.SessionState.InvokeCommand.GetCommand($CommandName, 'Function')).Parameters.Keys 6 | [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Name', 'InputObject', 'EnableException', 'Value' 7 | Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params | Should -BeNullOrEmpty 8 | } 9 | } 10 | } 11 | #TODO: Fix test for internal function 12 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricAPIclusterURI.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricAPIclusterURI' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricAPIclusterURI 14 | } 15 | 16 | Describe "Get-FabricAPIclusterURI" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should exist as a valid command' { 20 | $Command | Should -Not -BeNullOrEmpty 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FabricTools PowerShell Dev", 3 | "features": { 4 | "ghcr.io/devcontainers/features/powershell:1": {}, 5 | "ghcr.io/devcontainers/features/git:1": {}, 6 | "ghcr.io/devcontainers/features/common-utils:2": {}, 7 | "ghcr.io/devcontainers/features/azure-cli:1": {}, 8 | "ghcr.io/devcontainers/features/github-cli:1": {} 9 | }, 10 | 11 | "customizations": { 12 | "vscode": { 13 | "extensions": [ 14 | "davidanson.vscode-markdownlint", 15 | "ms-vscode.powershell", 16 | "streetsidesoftware.code-spell-checker", 17 | "redhat.vscode-yaml" 18 | ] 19 | } 20 | }, 21 | 22 | "settings": { 23 | "terminal.integrated.defaultProfile.linux": "pwsh" 24 | }, 25 | 26 | "postCreateCommand": "pwsh .devcontainer/post-create.ps1" 27 | } 28 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricAuthToken.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricAuthToken' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricAuthToken 14 | } 15 | 16 | Describe "Get-FabricAuthToken" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have no mandatory custom parameters' { 20 | # This command has no custom parameters, only common parameters 21 | $Command | Should -Not -BeNullOrEmpty 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | require_ci_to_pass: no 3 | # master should be the baseline for reporting 4 | branch: It lets you pause and resume Fabric capacities. 5 | 6 | comment: 7 | layout: "reach, diff, flags, files" 8 | behavior: default 9 | 10 | coverage: 11 | range: 50..80 12 | round: down 13 | precision: 0 14 | 15 | status: 16 | project: 17 | default: 18 | # Set the overall project code coverage requirement to 70% 19 | target: 70 20 | patch: 21 | default: 22 | # Set the pull request requirement to not regress overall coverage by more than 5% 23 | # and let codecov.io set the goal for the code changed in the patch. 24 | target: auto 25 | threshold: 5 26 | 27 | # Use this if there are paths that should not be part of the code coverage, for 28 | # example a deprecated function where tests has been removed. 29 | #ignore: 30 | # - 'source/Public/Get-Deprecated.ps1' 31 | 32 | -------------------------------------------------------------------------------- /helper/build-and-test.ps1: -------------------------------------------------------------------------------- 1 | $PSVersionTable 2 | 3 | Import-module PSScriptAnalyzer 4 | 5 | Find-Module Microsoft.PowerShell.PSResourceGet 6 | .\build.ps1 -ResolveDependency -Tasks noop -UsePSResourceGet 7 | 8 | 9 | ######### BUILD ######### 10 | 11 | ./build.ps1 -ResolveDependency -Tasks noop 12 | 13 | Remove-Module -Name FabricTools -ErrorAction SilentlyContinue 14 | ./build.ps1 -Tasks build 15 | ipmo .\output\module\FabricTools\0.0.1\FabricTools.psd1 16 | Get-Module Fab* 17 | 18 | Invoke-ScriptAnalyzer -Path .\source\Public\** 19 | 20 | 21 | $tests = Invoke-Pester .\tests\ -PassThru 22 | $tests.Tests | where Result -eq 'Failed' | Measure-Object | Select-Object -ExpandProperty Count 23 | $tests.Tests | where Result -eq 'Failed' | ft -Property ExpandedName, ErrorRecord 24 | $tests.Tests | where Result -eq 'Failed' | ft -Property Path, Result, ErrorRecord -AutoSize 25 | 26 | $e = $tests.Tests | where Result -eq 'Failed' | Select-Object -Last 1 27 | $e.ErrorRecord 28 | -------------------------------------------------------------------------------- /source/Public/Get-FabricDebugInfo.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDebugInfo { 2 | 3 | <# 4 | .SYNOPSIS 5 | Shows internal debug information about the current Azure & Fabric sessions & Fabric config. 6 | 7 | .DESCRIPTION 8 | Shows internal debug information about the current session. It is useful for troubleshooting purposes. 9 | It will show you the current session object. This includes the bearer token. This can be useful 10 | for connecting to the REST API directly via Postman. 11 | 12 | .Example 13 | Get-FabricDebugInfo 14 | 15 | This example shows the current session object. 16 | 17 | .NOTES 18 | 19 | Author: Frank Geisler, Kamil Nowinski 20 | 21 | #> 22 | 23 | [CmdletBinding()] 24 | [OutputType([System.Collections.Hashtable])] 25 | param ( ) 26 | 27 | return @{ 28 | FabricSession = $script:FabricSession 29 | AzureSession = $script:AzureSession 30 | FabricConfig = $script:FabricConfig 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /source/Public/Config/Get-FabricConfig.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricConfig { 2 | <# 3 | .SYNOPSIS 4 | Gets the configuration for use with all functions in the FabricTools module. 5 | 6 | .DESCRIPTION 7 | Gets the configuration for use with all functions in the FabricTools module. 8 | 9 | .PARAMETER ConfigName 10 | The name of the configuration to be retrieved. 11 | 12 | .EXAMPLE 13 | Gets all configuration values for the FabricTools module and outputs them. 14 | 15 | ```powershell 16 | Get-FabricConfig 17 | ``` 18 | 19 | .EXAMPLE 20 | Gets the BaseUrl configuration value for the FabricTools module. 21 | 22 | ```powershell 23 | Get-FabricConfig -ConfigName BaseUrl 24 | ``` 25 | 26 | .NOTES 27 | 28 | Author: Jess Pomfret 29 | 30 | #> 31 | param ( 32 | [String] $ConfigName 33 | ) 34 | 35 | if ($ConfigName) { 36 | Get-PSFConfig -Module 'FabricTools' -Name $ConfigName 37 | } else { 38 | Get-PSFConfig -Module 'FabricTools' 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricDebugInfo.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricDebugInfo' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricDebugInfo 14 | } 15 | 16 | Describe "Get-FabricDebugInfo" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have no mandatory custom parameters' { 20 | # This command has no custom parameters, only common parameters 21 | $Command | Should -Not -BeNullOrEmpty 22 | } 23 | } 24 | 25 | Context "Successful debug info retrieval" { 26 | It 'Should return debug information' { 27 | $result = Get-FabricDebugInfo 28 | $result | Should -Not -BeNullOrEmpty 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /GitVersion.yml: -------------------------------------------------------------------------------- 1 | mode: ContinuousDelivery 2 | next-version: 0.22.0 3 | major-version-bump-message: '(breaking\schange|breaking|major)\b' 4 | minor-version-bump-message: '(adds?|features?|minor)\b' 5 | patch-version-bump-message: '\s?(fix|patch)' 6 | no-bump-message: '\+semver:\s?(none|skip)' 7 | assembly-informational-format: '{NuGetVersionV2}+Sha.{Sha}.Date.{CommitDate}' 8 | branches: 9 | master: 10 | tag: preview 11 | regex: ^ It lets you pause and resume Fabric capacities.$ 12 | pull-request: 13 | tag: PR 14 | feature: 15 | tag: useBranchName 16 | increment: Minor 17 | regex: f(eature(s)?)?[\/-] 18 | source-branches: ['master'] 19 | hotfix: 20 | tag: fix 21 | increment: Patch 22 | regex: (hot)?fix(es)?[\/-] 23 | source-branches: ['master'] 24 | 25 | ignore: 26 | sha: [] 27 | merge-message-formats: {} 28 | 29 | 30 | # feature: 31 | # tag: useBranchName 32 | # increment: Minor 33 | # regex: f(eature(s)?)?[/-] 34 | # source-branches: ['master'] 35 | # hotfix: 36 | # tag: fix 37 | # increment: Patch 38 | # regex: (hot)?fix(es)?[/-] 39 | # source-branches: ['master'] 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 Data Platform Community 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /RequiredModules.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | <# 3 | This is only required if you need to use the method PowerShellGet & PSDepend 4 | It is not required for PSResourceGet or ModuleFast (and will be ignored). 5 | See Resolve-Dependency.psd1 on how to enable methods. 6 | #> 7 | #PSDependOptions = @{ 8 | # AddToPath = $true 9 | # Target = 'output\RequiredModules' 10 | # Parameters = @{ 11 | # Repository = 'PSGallery' 12 | # } 13 | #} 14 | Assert = "0.9.6" 15 | InvokeBuild = 'latest' 16 | PSScriptAnalyzer = '1.24.0' 17 | Pester = 'latest' 18 | ModuleBuilder = 'latest' 19 | ChangelogManagement = 'latest' 20 | Sampler = 'latest' 21 | 'Sampler.GitHubTasks' = 'latest' 22 | MarkdownLinkCheck = 'latest' 23 | 'PSFramework' = 'latest' 24 | 'Az.Accounts' = '5.3.0' 25 | 'Az.Resources' = '8.1.1' 26 | 'MicrosoftPowerBIMgmt' = '1.2.1111' 27 | 'Microsoft.PowerShell.PlatyPS' = 'latest' 28 | } 29 | -------------------------------------------------------------------------------- /source/Public/Get-FabricAuthToken.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricAuthToken { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the Fabric API authentication token. 5 | 6 | .DESCRIPTION 7 | The Get-FabricAuthToken function retrieves the Fabric API authentication token. 8 | If the token is not already set, the function fails. 9 | 10 | .EXAMPLE 11 | Get-FabricAuthToken 12 | 13 | This command retrieves the Fabric API authentication token. 14 | 15 | .INPUTS 16 | None. You cannot pipe inputs to this function. 17 | 18 | .OUTPUTS 19 | String. This function returns the Fabric API authentication token. 20 | 21 | .NOTES 22 | 23 | Author: Rui Romano 24 | 25 | #> 26 | [CmdletBinding()] 27 | param 28 | ( 29 | ) 30 | 31 | $accessToken = Get-PSFConfigValue FabricTools.FabricSession.AccessToken 32 | if ($accessToken) { 33 | $ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($accessToken.Token) 34 | $Token = ([System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)) 35 | return $Token 36 | } else { 37 | Write-Message -Message "AccessToken details are missing. Please run 'Connect-FabricAccount' to configure session." -Level Error 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /.devcontainer/post-create.ps1: -------------------------------------------------------------------------------- 1 | # post-create.ps1 2 | 3 | Write-Host "Running DevContainer post-create setup..." 4 | 5 | # Ensure scripts can run 6 | Set-ExecutionPolicy RemoteSigned -Scope Process -Force 7 | 8 | # Install/update PSResourceGet side-by-side 9 | Write-Host "Installing PSResourceGet..." 10 | Install-Module Microsoft.PowerShell.PSResourceGet -Force -AllowClobber 11 | 12 | # Install common modules used in this environment 13 | $requiredModules = @( 14 | "Pester", 15 | "Az.Accounts" 16 | ) 17 | 18 | Write-Host "Installing required modules..." 19 | foreach ($module in $requiredModules) { 20 | Install-Module $module -Repository PSGallery -Force -SkipPublisherCheck -AllowClobber 21 | } 22 | 23 | # Validate installation 24 | foreach ($module in $requiredModules) { 25 | if (-not (Get-Module -ListAvailable -Name $module)) { 26 | Write-Warning "Module [$module] did NOT install successfully!" 27 | } 28 | } 29 | 30 | # Display installed versions for debugging 31 | Write-Host "Installed module versions:" 32 | 33 | Get-Module -ListAvailable | 34 | Where-Object { $_.Name -in $requiredModules + "Microsoft.PowerShell.PSResourceGet" } | 35 | Sort-Object Name, Version | 36 | Format-Table Name, Version, ModuleBase 37 | -------------------------------------------------------------------------------- /helper/GetFunctionList.ps1: -------------------------------------------------------------------------------- 1 | $path = ".\source\public" 2 | $op = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object 3 | $op | Out-File '.\output\FunctionList-main-public.txt' 4 | 5 | # Author Table 6 | # This script generates a table of PowerShell script authors from the specified directory. 7 | $path = ".\source\public" 8 | $op = Get-ChildItem -Path $path -Recurse -Filter *.ps1 9 | $authorTable = @{} 10 | $op | ForEach-Object { 11 | $file = $_.FullName 12 | $name = $_.Name 13 | $content = Get-Content $file 14 | $authorLine = $content | Where-Object { $_ -match 'Author:\s*(.+)' } | Select-Object -First 1 15 | if ($authorLine -match 'Author:\s*(.+)') { 16 | $author = $matches[1].Trim() 17 | $authorTable[$name] = $author 18 | } else { 19 | $authorTable[$name] = $null 20 | } 21 | } 22 | $authorTable | ft -AutoSize 23 | $authorTable.GetEnumerator() | Where-Object { -not $_.Value } | ft -AutoSize 24 | 25 | 26 | 27 | ## Not a singular name option for functions (#26) 28 | Get-Command -Module FabricTools |where Name -like '*s' 29 | Get-Command -Module FabricTools|ForEach-Object { $name = $_.Name; $_.Parameters.Values | Where Name -like '*s' | Select @{N='FunctionName';E={$Name}},Name} 30 | -------------------------------------------------------------------------------- /source/Public/Capacity/Get-FabricCapacityTenantOverrides.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricCapacityTenantOverrides { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the tenant overrides for all capacities. 5 | 6 | .DESCRIPTION 7 | The Get-FabricCapacityTenantOverrides function retrieves the tenant overrides for all capacities. It supports multiple aliases for flexibility. 8 | 9 | .EXAMPLE 10 | This example retrieves the tenant overrides for all capacities. 11 | 12 | ```powershell 13 | Get-FabricCapacityTenantOverrides 14 | ``` 15 | 16 | .NOTES 17 | The function retrieves the PowerBI access token and makes a GET request to the Fabric API to retrieve the tenant overrides for all capacities. It then returns the response of the GET request. 18 | 19 | Author: Ioana Bouariu 20 | 21 | #> 22 | 23 | # This function retrieves the tenant overrides for all capacities. 24 | # Define aliases for the function for flexibility. 25 | [Alias("Get-FabCapacityTenantOverrides")] 26 | 27 | Param ( 28 | ) 29 | 30 | Confirm-TokenState 31 | 32 | # Make a GET request to the Fabric API to retrieve the tenant overrides for all capacities. 33 | # The function returns the response of the GET request. 34 | return Invoke-FabricRestMethod -uri "admin/capacities/delegatedTenantSettingOverrides" -Method GET 35 | } 36 | -------------------------------------------------------------------------------- /source/Public/Get-SHA256.ps1: -------------------------------------------------------------------------------- 1 | function Get-Sha256 ($string) { 2 | <# 3 | .SYNOPSIS 4 | Calculates the SHA256 hash of a string. 5 | 6 | .DESCRIPTION 7 | The Get-Sha256 function calculates the SHA256 hash of a string. 8 | 9 | .PARAMETER string 10 | The string to hash. This is a mandatory parameter. 11 | 12 | .EXAMPLE 13 | Get-Sha256 -string "your-string" 14 | 15 | This example calculates the SHA256 hash of a string. 16 | 17 | .NOTES 18 | The function creates a new SHA256CryptoServiceProvider object, converts the string to a byte array using UTF8 encoding, computes the SHA256 hash of the byte array, converts the hash to a string and removes any hyphens, and returns the resulting hash. 19 | 20 | Author: Ioana Bouariu 21 | 22 | #> 23 | 24 | # Create a new SHA256CryptoServiceProvider object. 25 | $sha256 = New-Object System.Security.Cryptography.SHA256CryptoServiceProvider 26 | 27 | # Convert the string to a byte array using UTF8 encoding. 28 | $bytes = [System.Text.Encoding]::UTF8.GetBytes($string) 29 | 30 | # Compute the SHA256 hash of the byte array. 31 | $hash = $sha256.ComputeHash($bytes) 32 | 33 | # Convert the hash to a string and remove any hyphens. 34 | $result = [System.BitConverter]::ToString($hash) -replace '-' 35 | 36 | # Return the resulting hash. 37 | return $result 38 | } 39 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricCapacityTenantOverrides.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricCapacityTenantOverrides 10 | --- 11 | 12 | # Get-FabricCapacityTenantOverrides 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the tenant overrides for all capacities. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricCapacityTenantOverrides 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | Get-FabCapacityTenantOverrides 29 | 30 | ## DESCRIPTION 31 | 32 | The Get-FabricCapacityTenantOverrides function retrieves the tenant overrides for all capacities. 33 | It supports multiple aliases for flexibility. 34 | 35 | ## EXAMPLES 36 | 37 | ### EXAMPLE 1 38 | 39 | This example retrieves the tenant overrides for all capacities. 40 | 41 | ```powershell 42 | Get-FabricCapacityTenantOverrides 43 | ``` 44 | 45 | ## PARAMETERS 46 | 47 | ## INPUTS 48 | 49 | ## OUTPUTS 50 | 51 | ## NOTES 52 | 53 | The function retrieves the PowerBI access token and makes a GET request to the Fabric API to retrieve the tenant overrides for all capacities. 54 | It then returns the response of the GET request. 55 | 56 | Author: Ioana Bouariu 57 | 58 | ## RELATED LINKS 59 | 60 | {{ Fill in the related links here }} 61 | 62 | -------------------------------------------------------------------------------- /source/Public/Get-FabricConnection.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricConnection { 2 | <# 3 | .SYNOPSIS 4 | Retrieves Fabric connections. 5 | 6 | .DESCRIPTION 7 | The Get-FabricConnection function retrieves Fabric connections. It can retrieve all connections or the specified one only. 8 | 9 | .PARAMETER connectionId 10 | The ID of the connection to retrieve. 11 | 12 | .EXAMPLE 13 | Get-FabricConnection 14 | 15 | This example retrieves all connections from Fabric 16 | 17 | .EXAMPLE 18 | Get-FabricConnection -connectionId "12345" 19 | 20 | This example retrieves specific connection from Fabric with ID "12345". 21 | 22 | .NOTES 23 | https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/get-connection?tabs=HTTP 24 | https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/list-connections?tabs=HTTP 25 | 26 | Author: Kamil Nowinski 27 | 28 | #> 29 | 30 | [CmdletBinding()] 31 | param 32 | ( 33 | [Parameter(Mandatory = $false)] 34 | [guid]$connectionId 35 | ) 36 | 37 | begin { 38 | Confirm-TokenState 39 | } 40 | 41 | process { 42 | if ($connectionId) { 43 | $result = Invoke-FabricRestMethod -Uri "/connections/$($connectionId)" -Method GET 44 | } else { 45 | $result = Invoke-FabricRestMethod -Uri "/connections" -Method GET 46 | } 47 | 48 | return $result.value 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /source/Private/Set-FabConfig.ps1: -------------------------------------------------------------------------------- 1 | Write-Verbose "Setting FabricTools configuration defaults..." 2 | 3 | Set-PSFConfig -Name 'FabricTools.FabricApi.BaseUrl' -Value 'https://api.fabric.microsoft.com/v1' 4 | Set-PSFConfig -Name 'FabricTools.FabricApi.ResourceUrl' -Value 'https://api.fabric.microsoft.com' 5 | Set-PSFConfig -Name 'FabricTools.FabricApi.TenantId' 6 | Set-PSFConfig -Name 'FabricTools.FabricApi.ContentType' -Value 'application/json; charset=utf-8' 7 | 8 | Set-PSFConfig -Name 'FabricTools.FabricSession.Headers' -Value @{} 9 | Set-PSFConfig -Name 'FabricTools.FabricSession.TokenExpiresOn' -Value $null 10 | Set-PSFConfig -Name 'FabricTools.FabricSession.AccessToken' -Value $null 11 | 12 | Set-PSFConfig -Name 'FabricTools.KustoApi.BaseUrl' -Value 'https://api.kusto.windows.net' 13 | Set-PSFConfig -Name 'FabricTools.AzureApi.BaseUrl' -Value "https://management.azure.com" 14 | 15 | Set-PSFConfig -Name 'FabricTools.AzureSession.AccessToken' -Value $null 16 | Set-PSFConfig -Name 'FabricTools.AzureSession.Headers' -Value @{} 17 | 18 | Set-PSFConfig -Name 'FabricTools.PowerBiApi.BaseUrl' -Value "https://api.powerbi.com/v1.0/myorg" 19 | 20 | # Remain backwards compatible with scripts relying on $FabricConfig variable 21 | $script:FabricConfig = @{ 22 | BaseUrl = "https://api.fabric.microsoft.com/v1" 23 | } 24 | 25 | # Feature Flags 26 | Set-PSFConfig -Name 'FabricTools.FeatureFlags.EnableTokenRefresh' -Value $true -Validation bool 27 | -------------------------------------------------------------------------------- /tests/Unit/Import-FabricItem.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Import-FabricItem' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Import-FabricItem 14 | } 15 | 16 | Describe "Import-FabricItem" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'path'; ExpectedParameterType = 'string'; Mandatory = 'False' } 21 | @{ ExpectedParameterName = 'workspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'False' } 22 | @{ ExpectedParameterName = 'filter'; ExpectedParameterType = 'string'; Mandatory = 'False' } 23 | @{ ExpectedParameterName = 'fileOverrides'; ExpectedParameterType = 'hashtable'; Mandatory = 'False' } 24 | ) { 25 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 26 | } 27 | 28 | It 'Should support ShouldProcess' { 29 | $Command.Parameters.ContainsKey('WhatIf') | Should -BeTrue 30 | $Command.Parameters.ContainsKey('Confirm') | Should -BeTrue 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /source/Private/Get-FabricContinuationToken.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricContinuationToken { 2 | <# 3 | .SYNOPSIS 4 | Internal function to handle continuation token logic for Fabric API calls. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricContinuationToken` function processes the API response to extract and handle continuation tokens. 8 | It returns the continuation token variable and provides debug logging. 9 | 10 | .PARAMETER Response 11 | The API response object that may contain a continuation token. 12 | 13 | .EXAMPLE 14 | Get-FabricContinuationToken -Response $response 15 | 16 | Processes the response and returns the continuation token if present. 17 | 18 | .NOTES 19 | This is an internal function used by other functions in the module. 20 | 21 | Author: Kamil Nowinski 22 | #> 23 | [CmdletBinding()] 24 | param ( 25 | [Parameter(Mandatory = $false)] 26 | [object]$Response 27 | ) 28 | 29 | $continuationToken = $null 30 | if ($null -ne $Response) { 31 | # Update the continuation token if present 32 | if ($Response.PSObject.Properties.Match("continuationToken") -and $Response.continuationToken -ne $null) { 33 | $continuationToken = $Response.continuationToken 34 | Write-Message -Message "New continuation token: $continuationToken" -Level Debug 35 | } else { 36 | Write-Message -Message "New continuation token to null" -Level Debug 37 | } 38 | } else { 39 | Write-Message -Message "No data received from the API." -Level Warning 40 | } 41 | $continuationToken 42 | } 43 | -------------------------------------------------------------------------------- /source/Public/Capacity/Get-FabricCapacityRefreshables.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricCapacityRefreshables { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the top refreshable capacities for the tenant. 5 | 6 | .DESCRIPTION 7 | The Get-FabricCapacityRefreshables function retrieves the top refreshable capacities for the tenant. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER top 10 | The number of top refreshable capacities to retrieve. This is a mandatory parameter. 11 | 12 | .EXAMPLE 13 | This example retrieves the top 5 refreshable capacities for the tenant. 14 | 15 | ```powershell 16 | Get-FabricCapacityRefreshables -top 5 17 | ``` 18 | 19 | .NOTES 20 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the top refreshable capacities. It then returns the 'value' property of the response, which contains the capacities. 21 | 22 | Author: Ioana Bouariu 23 | 24 | #> 25 | 26 | # Define aliases for the function for flexibility. 27 | [Alias("Get-FabCapacityRefreshables")] 28 | 29 | # Define a mandatory parameter for the number of top refreshable capacities to retrieve. 30 | Param ( 31 | [Parameter(Mandatory = $false)] 32 | [string]$top = 5 33 | ) 34 | 35 | Confirm-TokenState 36 | 37 | # Make a GET request to the PowerBI API to retrieve the top refreshable capacities. 38 | # The function returns the 'value' property of the response. 39 | $result = Invoke-FabricRestMethod -Method GET -PowerBIApi -Uri "capacities/refreshables?`$top=$top" 40 | $result.value 41 | } 42 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricAuthToken.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricAuthToken 10 | --- 11 | 12 | # Get-FabricAuthToken 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the Fabric API authentication token. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricAuthToken [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The Get-FabricAuthToken function retrieves the Fabric API authentication token. 31 | If the token is not already set, the function fails. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Get-FabricAuthToken 38 | 39 | This command retrieves the Fabric API authentication token. 40 | 41 | ## PARAMETERS 42 | 43 | ### CommonParameters 44 | 45 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 46 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 47 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 48 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 49 | 50 | ## INPUTS 51 | 52 | ### None. You cannot pipe inputs to this function. 53 | 54 | {{ Fill in the Description }} 55 | 56 | ## OUTPUTS 57 | 58 | ### String. This function returns the Fabric API authentication token. 59 | 60 | {{ Fill in the Description }} 61 | 62 | ## NOTES 63 | 64 | Author: Rui Romano 65 | 66 | ## RELATED LINKS 67 | 68 | {{ Fill in the related links here }} 69 | 70 | -------------------------------------------------------------------------------- /tests/Unit/Convert-FromBase64.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Convert-FromBase64' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Convert-FromBase64 14 | } 15 | 16 | Describe "Convert-FromBase64" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'Base64String'; ExpectedParameterType = 'string'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful Base64 conversion" { 27 | It 'Should convert Base64 string back to original text' { 28 | $originalText = 'Hello World' 29 | $base64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($originalText)) 30 | $result = Convert-FromBase64 -Base64String $base64 31 | $result | Should -Be $originalText 32 | } 33 | } 34 | 35 | Context "Error handling" { 36 | It 'Should handle invalid Base64 string gracefully' { 37 | { Convert-FromBase64 -Base64String 'NotValidBase64!!!' } | Should -Throw 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /source/Public/Get-FabricAPIClusterURI.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricAPIclusterURI { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the cluster URI for the tenant. 5 | 6 | .DESCRIPTION 7 | The Get-FabricAPIclusterURI function retrieves the cluster URI for the tenant. It supports multiple aliases for flexibility. 8 | 9 | .EXAMPLE 10 | Get-FabricAPIclusterURI 11 | 12 | This example retrieves the cluster URI for the tenant. 13 | 14 | .NOTES 15 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the datasets. It then extracts the '@odata.context' property from the response, splits it on the '/' character, and selects the third element. This element is used to construct the cluster URI, which is then returned by the function. 16 | 17 | Author: Ioana Bouariu 18 | 19 | #> 20 | 21 | # Define aliases for the function for flexibility. 22 | [Alias("Get-FabAPIClusterURI")] 23 | [CmdletBinding()] 24 | [OutputType([string])] 25 | Param ( 26 | ) 27 | 28 | Confirm-TokenState 29 | 30 | # Make a GET request to the PowerBI API to retrieve the datasets. 31 | $reply = Invoke-FabricRestMethod -Method GET -PowerBIApi -Uri "datasets" 32 | 33 | # Extract the '@odata.context' property from the response. 34 | $unaltered = $reply.'@odata.context' 35 | 36 | # Split the '@odata.context' property on the '/' character and select the third element. 37 | $stripped = $unaltered.split('/')[2] 38 | 39 | # Construct the cluster URI. 40 | $clusterURI = "https://$stripped/beta/myorg/groups" 41 | 42 | # Return the cluster URI. 43 | return $clusterURI 44 | } 45 | -------------------------------------------------------------------------------- /docs/en-US/Get-Sha256.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-Sha256 10 | --- 11 | 12 | # Get-Sha256 13 | 14 | ## SYNOPSIS 15 | 16 | Calculates the SHA256 hash of a string. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-Sha256 [[-string] ] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The Get-Sha256 function calculates the SHA256 hash of a string. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | Get-Sha256 -string "your-string" 37 | 38 | This example calculates the SHA256 hash of a string. 39 | 40 | ## PARAMETERS 41 | 42 | ### -string 43 | 44 | The string to hash. 45 | This is a mandatory parameter. 46 | 47 | ```yaml 48 | Type: System.Object 49 | DefaultValue: '' 50 | SupportsWildcards: false 51 | Aliases: [] 52 | ParameterSets: 53 | - Name: (All) 54 | Position: 0 55 | IsRequired: false 56 | ValueFromPipeline: false 57 | ValueFromPipelineByPropertyName: false 58 | ValueFromRemainingArguments: false 59 | DontShow: false 60 | AcceptedValues: [] 61 | HelpMessage: '' 62 | ``` 63 | 64 | ## INPUTS 65 | 66 | ## OUTPUTS 67 | 68 | ## NOTES 69 | 70 | The function creates a new SHA256CryptoServiceProvider object, converts the string to a byte array using UTF8 encoding, computes the SHA256 hash of the byte array, converts the hash to a string and removes any hyphens, and returns the resulting hash. 71 | 72 | Author: Ioana Bouariu 73 | 74 | ## RELATED LINKS 75 | 76 | {{ Fill in the related links here }} 77 | 78 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricConfig.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricConfig 10 | --- 11 | 12 | # Get-FabricConfig 13 | 14 | ## SYNOPSIS 15 | 16 | Gets the configuration for use with all functions in the FabricTools module. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricConfig [[-ConfigName] ] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | Gets the configuration for use with all functions in the FabricTools module. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | Gets all configuration values for the FabricTools module and outputs them. 37 | 38 | ```powershell 39 | Get-FabricConfig 40 | ``` 41 | 42 | ### EXAMPLE 2 43 | 44 | Gets the BaseUrl configuration value for the FabricTools module. 45 | 46 | ```powershell 47 | Get-FabricConfig -ConfigName BaseUrl 48 | ``` 49 | 50 | ## PARAMETERS 51 | 52 | ### -ConfigName 53 | 54 | The name of the configuration to be retrieved. 55 | 56 | ```yaml 57 | Type: System.String 58 | DefaultValue: '' 59 | SupportsWildcards: false 60 | Aliases: [] 61 | ParameterSets: 62 | - Name: (All) 63 | Position: 0 64 | IsRequired: false 65 | ValueFromPipeline: false 66 | ValueFromPipelineByPropertyName: false 67 | ValueFromRemainingArguments: false 68 | DontShow: false 69 | AcceptedValues: [] 70 | HelpMessage: '' 71 | ``` 72 | 73 | ## INPUTS 74 | 75 | ## OUTPUTS 76 | 77 | ## NOTES 78 | 79 | Author: Jess Pomfret 80 | 81 | ## RELATED LINKS 82 | 83 | {{ Fill in the related links here }} 84 | -------------------------------------------------------------------------------- /tests/Unit/Update-FabricCapacityTenantSettingOverrides.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Update-FabricCapacityTenantSettingOverrides' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Update-FabricCapacityTenantSettingOverrides 14 | } 15 | 16 | Describe "Update-FabricCapacityTenantSettingOverrides" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'EnableTenantSetting'; ExpectedParameterType = 'bool'; Mandatory = 'True' } 21 | @{ ExpectedParameterName = 'DelegateToWorkspace'; ExpectedParameterType = 'bool'; Mandatory = 'False' } 22 | @{ ExpectedParameterName = 'EnabledSecurityGroups'; ExpectedParameterType = 'Object'; Mandatory = 'False' } 23 | @{ ExpectedParameterName = 'ExcludedSecurityGroups'; ExpectedParameterType = 'Object'; Mandatory = 'False' } 24 | ) { 25 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 26 | } 27 | 28 | It 'Should support ShouldProcess' { 29 | $Command.Parameters.ContainsKey('WhatIf') | Should -BeTrue 30 | $Command.Parameters.ContainsKey('Confirm') | Should -BeTrue 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricDebugInfo.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricDebugInfo 10 | --- 11 | 12 | # Get-FabricDebugInfo 13 | 14 | ## SYNOPSIS 15 | 16 | Shows internal debug information about the current Azure & Fabric sessions & Fabric config. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricDebugInfo [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | Shows internal debug information about the current session. 31 | It is useful for troubleshooting purposes. 32 | It will show you the current session object. 33 | This includes the bearer token. 34 | This can be useful 35 | for connecting to the REST API directly via Postman. 36 | 37 | ## EXAMPLES 38 | 39 | ### EXAMPLE 1 40 | 41 | Get-FabricDebugInfo 42 | 43 | This example shows the current session object. 44 | 45 | ## PARAMETERS 46 | 47 | ### CommonParameters 48 | 49 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 50 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 51 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 52 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 53 | 54 | ## INPUTS 55 | 56 | ## OUTPUTS 57 | 58 | ### System.Collections.Hashtable 59 | 60 | {{ Fill in the Description }} 61 | 62 | ## NOTES 63 | 64 | Author: Frank Geisler, Kamil Nowinski 65 | 66 | ## RELATED LINKS 67 | 68 | {{ Fill in the related links here }} 69 | 70 | -------------------------------------------------------------------------------- /tests/Unit/Convert-ToBase64.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Convert-ToBase64' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Convert-ToBase64 14 | } 15 | 16 | Describe "Convert-ToBase64" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'filePath'; ExpectedParameterType = 'string'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful Base64 conversion" { 27 | BeforeAll { 28 | $testFilePath = Join-Path $TestDrive 'testfile.txt' 29 | Set-Content -Path $testFilePath -Value 'Hello World' 30 | } 31 | 32 | It 'Should convert file to Base64 string' { 33 | $result = Convert-ToBase64 -filePath $testFilePath 34 | $result | Should -Not -BeNullOrEmpty 35 | $result | Should -BeOfType [string] 36 | } 37 | } 38 | 39 | Context "Error handling" { 40 | It 'Should throw when file does not exist' { 41 | { Convert-ToBase64 -filePath 'C:\nonexistent\file.txt' } | Should -Throw 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Unit/Connect-FabricAccount.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Connect-FabricAccount' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Connect-FabricAccount 14 | } 15 | 16 | Describe "Connect-FabricAccount" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'TenantId'; ExpectedParameterType = 'guid'; Mandatory = 'False' } 21 | @{ ExpectedParameterName = 'ServicePrincipalId'; ExpectedParameterType = 'guid'; Mandatory = 'False' } 22 | @{ ExpectedParameterName = 'ServicePrincipalSecret'; ExpectedParameterType = 'securestring'; Mandatory = 'False' } 23 | @{ ExpectedParameterName = 'Credential'; ExpectedParameterType = 'pscredential'; Mandatory = 'False' } 24 | @{ ExpectedParameterName = 'Reset'; ExpectedParameterType = 'switch'; Mandatory = 'False' } 25 | ) { 26 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 27 | } 28 | 29 | It 'Should support ShouldProcess' { 30 | $Command.Parameters.ContainsKey('WhatIf') | Should -BeTrue 31 | $Command.Parameters.ContainsKey('Confirm') | Should -BeTrue 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricExternalDataShares.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricExternalDataShares 10 | --- 11 | 12 | # Get-FabricExternalDataShares 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves External Data Shares details from a specified Microsoft Fabric. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricExternalDataShares [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | This function retrieves External Data Shares details. 31 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | This example retrieves the External Data Shares details 38 | 39 | ```powershell 40 | Get-FabricExternalDataShares 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### CommonParameters 46 | 47 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 48 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 49 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 50 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ## NOTES 57 | 58 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 59 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 60 | 61 | Author: Tiago Balabuch 62 | 63 | ## RELATED LINKS 64 | 65 | {{ Fill in the related links here }} 66 | 67 | -------------------------------------------------------------------------------- /source/Public/Capacity/Get-FabricCapacityWorkload.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricCapacityWorkload { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the workloads for a specific capacity. 5 | 6 | .DESCRIPTION 7 | The Get-FabricCapacityWorkload function retrieves the workloads for a specific capacity. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER capacityID 10 | The ID of the capacity. This is a mandatory parameter. 11 | 12 | .EXAMPLE 13 | This example retrieves the workloads for a specific capacity given the capacity ID and authentication token. 14 | 15 | ```powershell 16 | Get-FabricCapacityWorkload -capacityID "your-capacity-id" 17 | ``` 18 | 19 | .NOTES 20 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the workloads for the specified capacity. It then returns the 'value' property of the response, which contains the workloads. 21 | 22 | Author: Ioana Bouariu 23 | 24 | #> 25 | 26 | # This function retrieves the workloads for a specific capacity. 27 | # Define aliases for the function for flexibility. 28 | [Alias("Get-FabCapacityWorkload")] 29 | 30 | # Define a mandatory parameter for the capacity ID. 31 | Param ( 32 | [Parameter(Mandatory = $true)] 33 | [guid]$CapacityId 34 | ) 35 | 36 | Confirm-TokenState 37 | 38 | # Make a GET request to the PowerBI API to retrieve the workloads for the specified capacity. 39 | # The function returns the 'value' property of the response. 40 | $result = Invoke-FabricRestMethod -Method GET -PowerBIApi -Uri "capacities/$capacityID/Workloads" 41 | $result.value 42 | } 43 | 44 | 45 | #https://learn.microsoft.com/en-us/rest/api/power-bi/capacities/get-workloads 46 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Resource_proposal.yml: -------------------------------------------------------------------------------- 1 | name: New function proposal 2 | description: If you have a new function proposal that you think should be added to this module. 3 | title: "NewFunctionName: New resource proposal" 4 | labels: [] 5 | assignees: [] 6 | body: 7 | - type: markdown 8 | attributes: 9 | value: | 10 | Please replace `NewFunctionName` in the issue title (above) with your proposed function name. 11 | 12 | Thank you for contributing and making FabricTools better! 13 | - type: textarea 14 | id: description 15 | attributes: 16 | label: Function proposal 17 | description: Provide information how this function will/should work and how it will help users. 18 | validations: 19 | required: true 20 | - type: textarea 21 | id: proposedProperties 22 | attributes: 23 | label: Proposed properties 24 | description: | 25 | List all the proposed properties and parameters that the function should have. 26 | value: | 27 | Parameter | Description | Data type | Default value | Allowed values 28 | --- | --- | --- | --- | --- 29 | ParameterName | Detailed description | String | None | Any 30 | 31 | Property | Description 32 | --- | --- 33 | PropertyName | Detailed description 34 | validations: 35 | required: true 36 | - type: textarea 37 | id: considerations 38 | attributes: 39 | label: Special considerations or limitations 40 | description: | 41 | Provide any considerations or limitations you can think of that a contributor should take in account when coding the proposed function, and or what limitations a user will encounter or should consider when using the proposed function. 42 | validations: 43 | required: true 44 | -------------------------------------------------------------------------------- /.vscode/analyzersettings.psd1: -------------------------------------------------------------------------------- 1 | @{ 2 | CustomRulePath = '.\output\RequiredModules\DscResource.AnalyzerRules' 3 | includeDefaultRules = $true 4 | IncludeRules = @( 5 | # DSC Resource Kit style guideline rules. 6 | 'PSAvoidDefaultValueForMandatoryParameter', 7 | 'PSAvoidDefaultValueSwitchParameter', 8 | 'PSAvoidInvokingEmptyMembers', 9 | 'PSAvoidNullOrEmptyHelpMessageAttribute', 10 | 'PSAvoidUsingCmdletAliases', 11 | 'PSAvoidUsingComputerNameHardcoded', 12 | 'PSAvoidUsingDeprecatedManifestFields', 13 | 'PSAvoidUsingEmptyCatchBlock', 14 | 'PSAvoidUsingInvokeExpression', 15 | 'PSAvoidUsingPositionalParameters', 16 | 'PSAvoidShouldContinueWithoutForce', 17 | 'PSAvoidUsingWMICmdlet', 18 | 'PSAvoidUsingWriteHost', 19 | 'PSDSCReturnCorrectTypesForDSCFunctions', 20 | 'PSDSCStandardDSCFunctionsInResource', 21 | 'PSDSCUseIdenticalMandatoryParametersForDSC', 22 | 'PSDSCUseIdenticalParametersForDSC', 23 | 'PSMisleadingBacktick', 24 | 'PSMissingModuleManifestField', 25 | 'PSPossibleIncorrectComparisonWithNull', 26 | 'PSProvideCommentHelp', 27 | 'PSReservedCmdletChar', 28 | 'PSReservedParams', 29 | 'PSUseApprovedVerbs', 30 | 'PSUseCmdletCorrectly', 31 | 'PSUseOutputTypeCorrectly', 32 | 'PSAvoidGlobalVars', 33 | 'PSAvoidUsingConvertToSecureStringWithPlainText', 34 | 'PSAvoidUsingPlainTextForPassword', 35 | 'PSAvoidUsingUsernameAndPasswordParams', 36 | 'PSDSCUseVerboseMessageInDSCResource', 37 | 'PSShouldProcess', 38 | 'PSUseDeclaredVarsMoreThanAssignments', 39 | 'PSUsePSCredentialType', 40 | 41 | 'Measure-*' 42 | ) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/Problem_with_resource.yml: -------------------------------------------------------------------------------- 1 | name: Problem with a function 2 | description: If you have a problem, bug, or enhancement with a function in this module. 3 | labels: [] 4 | assignees: [] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Please prefix the issue title (above) with the function name, e.g. 'FunctionName: Short description of my issue'! 10 | 11 | Your feedback and support is greatly appreciated, thanks for contributing! 12 | - type: textarea 13 | id: description 14 | attributes: 15 | label: Problem description 16 | description: Details of the scenario you tried and the problem that is occurring. 17 | validations: 18 | required: true 19 | - type: textarea 20 | id: logs 21 | attributes: 22 | label: Verbose logs 23 | description: | 24 | Verbose logs showing the problem. **NOTE! Sensitive information should be obfuscated.** _Will be automatically formatted as plain text._ 25 | placeholder: | 26 | Paste verbose logs here 27 | render: text 28 | validations: 29 | required: true 30 | - type: textarea 31 | id: version 32 | attributes: 33 | label: Module Version 34 | description: | 35 | The version of the FabricTools module you are using. _Will be automatically formatted as plain text._ 36 | To help with this information, please run this command: `Get-Module -Name 'FabricTools' | ft Name,Version,Path` 37 | placeholder: | 38 | Paste output here 39 | validations: 40 | required: true 41 | - type: textarea 42 | id: suggestedSolution 43 | attributes: 44 | label: Suggested solution 45 | description: Do you have any suggestions how to solve the issue? 46 | validations: 47 | required: true 48 | -------------------------------------------------------------------------------- /tests/Unit/Get-Sha256.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-Sha256' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-Sha256 14 | } 15 | 16 | Describe "Get-Sha256" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'string'; ExpectedParameterType = 'object'; Mandatory = 'False' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful SHA256 hash computation" { 27 | It 'Should compute SHA256 hash for a string' { 28 | $result = Get-Sha256 -string 'Hello World' 29 | $result | Should -Not -BeNullOrEmpty 30 | $result | Should -BeOfType [string] 31 | $result.Length | Should -Be 64 # SHA256 produces 64 hex characters 32 | } 33 | 34 | It 'Should produce consistent hash for same input' { 35 | $result1 = Get-Sha256 -string 'Test' 36 | $result2 = Get-Sha256 -string 'Test' 37 | $result1 | Should -Be $result2 38 | } 39 | 40 | It 'Should produce different hash for different input' { 41 | $result1 = Get-Sha256 -string 'Hello' 42 | $result2 = Get-Sha256 -string 'World' 43 | $result1 | Should -Not -Be $result2 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /source/Public/Capacity/Get-FabricCapacitySkus.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricCapacitySkus { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the fabric capacity information. 5 | 6 | .DESCRIPTION 7 | This function makes a GET request to the Fabric API to retrieve the tenant settings. 8 | 9 | .PARAMETER subscriptionID 10 | Specifies the subscription ID for the Azure subscription. 11 | 12 | .PARAMETER ResourceGroupName 13 | Specifies the name of the resource group in which the Fabric capacity is located. 14 | 15 | .PARAMETER capacity 16 | Specifies the capacity to retrieve information for. If not provided, all capacities will be retrieved. 17 | 18 | .EXAMPLE 19 | Retrieves the fabric capacity information for the specified capacity. 20 | 21 | ```powershell 22 | Get-FabricCapacitySkus -capacity "exampleCapacity" 23 | ``` 24 | 25 | .NOTES 26 | 27 | Author: Kamil Nowinski 28 | 29 | #> 30 | 31 | Param( 32 | [Parameter(Mandatory = $true)] 33 | [guid]$subscriptionID, 34 | [Parameter(Mandatory = $true)] 35 | [string]$ResourceGroupName, 36 | [Parameter(Mandatory = $true)] 37 | [string]$capacity 38 | ) 39 | 40 | Confirm-TokenState 41 | 42 | $AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl' 43 | $AzureSessionHeaderParams = Get-PSFConfigValue 'FabricTools.AzureSession.Headers' 44 | 45 | #GET https://management.azure.com/subscriptions/548B7FB7-3B2A-4F46-BB02-66473F1FC22C/resourceGroups/TestRG/providers/Microsoft.Fabric/capacities/azsdktest/skus?api-version=2023-11-01 46 | $uri = "$AzureBaseApiUrl/subscriptions/$subscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.Fabric/capacities/$capacity/skus?api-version=2023-11-01" 47 | $result = Invoke-RestMethod -Headers $AzureSessionHeaderParams -Uri $uri -Method GET 48 | 49 | return $result.value 50 | 51 | } 52 | -------------------------------------------------------------------------------- /source/Public/Dashboard/Get-FabricDashboard.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDashboard { 2 | <# 3 | .SYNOPSIS 4 | Retrieves dashboards from a specified workspace. 5 | 6 | .DESCRIPTION 7 | This function retrieves all dashboards from a specified workspace using the provided WorkspaceId. 8 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 9 | 10 | .PARAMETER WorkspaceId 11 | The ID of the workspace from which to retrieve dashboards. This parameter is mandatory. 12 | 13 | .EXAMPLE 14 | This example retrieves all dashboards from the workspace with ID "12345". 15 | 16 | ```powershell 17 | Get-FabricDashboard -WorkspaceId "12345" 18 | ``` 19 | 20 | .NOTES 21 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 22 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 23 | 24 | Author: Tiago Balabuch 25 | #> 26 | [CmdletBinding()] 27 | param ( 28 | [Parameter(Mandatory = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [guid]$WorkspaceId 31 | ) 32 | 33 | try { 34 | # Ensure token validity 35 | Confirm-TokenState 36 | 37 | # Construct the API endpoint URL 38 | $apiEndpointURI = "workspaces/{0}/dashboards" -f $WorkspaceId 39 | 40 | # Invoke the Fabric API to retrieve capacity details 41 | $apiParams = @{ 42 | Uri = $apiEndpointURI 43 | Method = 'Get' 44 | } 45 | $Dashboards = Invoke-FabricRestMethod @apiParams 46 | 47 | return $Dashboards 48 | 49 | } catch { 50 | # Capture and log error details 51 | $errorDetails = $_.Exception.Message 52 | Write-Message -Message "Failed to retrieve Dashboard. Error: $errorDetails" -Level Error 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricAPIclusterURI.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricAPIclusterURI 10 | --- 11 | 12 | # Get-FabricAPIclusterURI 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the cluster URI for the tenant. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricAPIclusterURI [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | Get-FabAPIClusterURI 29 | 30 | ## DESCRIPTION 31 | 32 | The Get-FabricAPIclusterURI function retrieves the cluster URI for the tenant. 33 | It supports multiple aliases for flexibility. 34 | 35 | ## EXAMPLES 36 | 37 | ### EXAMPLE 1 38 | 39 | Get-FabricAPIclusterURI 40 | 41 | This example retrieves the cluster URI for the tenant. 42 | 43 | ## PARAMETERS 44 | 45 | ### CommonParameters 46 | 47 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 48 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 49 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 50 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ### System.String 57 | 58 | {{ Fill in the Description }} 59 | 60 | ## NOTES 61 | 62 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the datasets. 63 | It then extracts the '@odata.context' property from the response, splits it on the '/' character, and selects the third element. 64 | This element is used to construct the cluster URI, which is then returned by the function. 65 | 66 | Author: Ioana Bouariu 67 | 68 | ## RELATED LINKS 69 | 70 | {{ Fill in the related links here }} 71 | 72 | -------------------------------------------------------------------------------- /source/Public/Invoke-FabricDatasetRefresh.ps1: -------------------------------------------------------------------------------- 1 | function Invoke-FabricDatasetRefresh { 2 | <# 3 | .SYNOPSIS 4 | This function invokes a refresh of a PowerBI dataset 5 | 6 | .DESCRIPTION 7 | The Invoke-FabricDatasetRefresh function is used to refresh a PowerBI dataset. It first checks if the dataset is refreshable. If it is not, it writes an error. If it is, it invokes a PowerBI REST method to refresh the dataset. The URL for the request is constructed using the provided dataset ID. 8 | 9 | .PARAMETER DatasetID 10 | A mandatory parameter that specifies the dataset ID. 11 | 12 | .EXAMPLE 13 | Invoke-FabricDatasetRefresh -DatasetID "12345678-1234-1234-1234-123456789012" 14 | 15 | This command invokes a refresh of the dataset with the ID "12345678-1234-1234-1234-123456789012" 16 | 17 | .NOTES 18 | Alias: Invoke-FabDatasetRefresh 19 | 20 | Author: Ioana Bouariu 21 | 22 | #> 23 | # Define aliases for the function for flexibility. 24 | [Alias("Invoke-FabDatasetRefresh")] 25 | 26 | # Define parameters for the workspace ID and dataset ID. 27 | param( 28 | # Mandatory parameter for the dataset ID 29 | [Parameter(Mandatory = $true, ParameterSetName = "DatasetId")] 30 | [guid]$DatasetID 31 | ) 32 | 33 | Confirm-TokenState 34 | 35 | # Check if the dataset is refreshable 36 | if ((Get-FabricDataset -DatasetId $DatasetID).isrefreshable -eq $false) { 37 | # If the dataset is not refreshable, write an error 38 | Write-Error "Dataset is not refreshable" 39 | } else { 40 | # If the dataset is refreshable, invoke a PowerBI REST method to refresh the dataset 41 | # The URL for the request is constructed using the provided workspace ID and dataset ID. 42 | Invoke-FabricRestMethod -Method POST -PowerBIApi -Uri "datasets/$DatasetID/refreshes" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /source/Public/Utils/Convert-FromBase64.ps1: -------------------------------------------------------------------------------- 1 | function Convert-FromBase64 { 2 | <# 3 | .SYNOPSIS 4 | Decodes a Base64-encoded string into its original text representation. 5 | 6 | .DESCRIPTION 7 | The Convert-FromBase64 function takes a Base64-encoded string as input, decodes it into a byte array, 8 | and converts it back into a UTF-8 encoded string. It is useful for reversing Base64 encoding applied 9 | to text or other data. 10 | 11 | .PARAMETER Base64String 12 | The Base64-encoded string that you want to decode. 13 | 14 | .EXAMPLE 15 | Output: Hello, World! 16 | 17 | ```powershell 18 | Convert-FromBase64 -Base64String "SGVsbG8sIFdvcmxkIQ==" 19 | ``` 20 | 21 | .EXAMPLE 22 | Output: Some encoded text 23 | 24 | ```powershell 25 | $encodedString = "U29tZSBlbmNvZGVkIHRleHQ=" 26 | Convert-FromBase64 -Base64String $encodedString 27 | ``` 28 | 29 | .NOTES 30 | This function assumes the Base64 input is a valid UTF-8 encoded string. 31 | Any decoding errors will throw a descriptive error message. 32 | 33 | Author: Tiago Balabuch 34 | 35 | #> 36 | 37 | param ( 38 | [Parameter(Mandatory = $true)] 39 | [string]$Base64String 40 | ) 41 | 42 | try { 43 | # Step 1: Convert the Base64 string to a byte array 44 | $bytes = [Convert]::FromBase64String($Base64String) 45 | 46 | # Step 2: Convert the byte array back to a UTF-8 string 47 | $decodedString = [System.Text.Encoding]::UTF8.GetString($bytes) 48 | 49 | # Step 3: Return the decoded string 50 | return $decodedString 51 | } catch { 52 | # Step 4: Handle and log errors 53 | $errorDetails = $_.Exception.Message 54 | Write-Message -Message "An error occurred while decoding from Base64: $errorDetails" -Level Error 55 | throw "An error occurred while decoding from Base64: $_" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "powershell.codeFormatting.openBraceOnSameLine": false, 3 | "powershell.codeFormatting.newLineAfterOpenBrace": true, 4 | "powershell.codeFormatting.newLineAfterCloseBrace": true, 5 | "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, 6 | "powershell.codeFormatting.whitespaceBeforeOpenParen": true, 7 | "powershell.codeFormatting.whitespaceAroundOperator": true, 8 | "powershell.codeFormatting.whitespaceAfterSeparator": true, 9 | "powershell.codeFormatting.ignoreOneLineBlock": false, 10 | "powershell.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline", 11 | "powershell.codeFormatting.preset": "Custom", 12 | "powershell.codeFormatting.alignPropertyValuePairs": true, 13 | "powershell.developer.bundledModulesPath": "${cwd}/output/RequiredModules", 14 | "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1", 15 | "powershell.scriptAnalysis.enable": true, 16 | "files.trimTrailingWhitespace": true, 17 | "files.trimFinalNewlines": true, 18 | "files.insertFinalNewline": true, 19 | "files.associations": { 20 | "*.ps1xml": "xml" 21 | }, 22 | "cSpell.words": [ 23 | "Balabuch", 24 | "buildhelpers", 25 | "COMPANYNAME", 26 | "endregion", 27 | "gitversion", 28 | "icontains", 29 | "ICONURI", 30 | "keepachangelog", 31 | "LICENSEURI", 32 | "notin", 33 | "PROJECTURI", 34 | "pscmdlet", 35 | "RELEASENOTES", 36 | "steppable" 37 | ], 38 | "[markdown]": { 39 | "files.trimTrailingWhitespace": false, 40 | "files.encoding": "utf8" 41 | }, 42 | "github.copilot.chat.commitMessageGeneration.instructions": [ 43 | { 44 | "file": ".github/copilot-commit-message-instructions.md" 45 | } 46 | ] 47 | } 48 | -------------------------------------------------------------------------------- /source/Public/External Data Share/Get-FabricExternalDataShares.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricExternalDataShares { 2 | <# 3 | .SYNOPSIS 4 | Retrieves External Data Shares details from a specified Microsoft Fabric. 5 | 6 | .DESCRIPTION 7 | This function retrieves External Data Shares details. 8 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 9 | 10 | .EXAMPLE 11 | This example retrieves the External Data Shares details 12 | 13 | ```powershell 14 | Get-FabricExternalDataShares 15 | ``` 16 | 17 | .NOTES 18 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 19 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 20 | 21 | Author: Tiago Balabuch 22 | #> 23 | [CmdletBinding()] 24 | param ( ) 25 | 26 | try { 27 | 28 | # Validate authentication token before proceeding 29 | Confirm-TokenState 30 | 31 | # Construct the API endpoint URI for retrieving external data shares 32 | Write-Message -Message "Constructing API endpoint URI..." -Level Debug 33 | $apiEndpointURI = "{0}/admin/items/externalDataShares" -f $FabricConfig.BaseUrl, $WorkspaceId 34 | 35 | # Invoke the API request to retrieve external data shares 36 | $externalDataShares = Invoke-FabricRestMethod ` 37 | -Uri $apiEndpointURI ` 38 | -Method Get 39 | 40 | # Return the retrieved external data shares 41 | Write-Message -Message "Successfully retrieved external data shares." -Level Debug 42 | return $externalDataShares 43 | } catch { 44 | # Capture and log detailed error information if the API request fails 45 | $errorDetails = $_.Exception.Message 46 | Write-Message -Message "Failed to retrieve External Data Shares. Error: $errorDetails" -Level Error 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricWorkspaceTenantSettingOverrides.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricWorkspaceTenantSettingOverrides 10 | --- 11 | 12 | # Get-FabricWorkspaceTenantSettingOverrides 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves tenant setting overrides for all workspaces in the Fabric tenant. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricWorkspaceTenantSettingOverrides [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Get-FabricWorkspaceTenantSettingOverrides` function retrieves tenant setting overrides for all workspaces in the Fabric tenant by making a GET request to the appropriate API endpoint. 31 | The function validates the authentication token before making the request and handles the response accordingly. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Returns all workspaces tenant setting overrides. 38 | 39 | ```powershell 40 | Get-FabricWorkspaceTenantSettingOverrides 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### CommonParameters 46 | 47 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 48 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 49 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 50 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ## NOTES 57 | 58 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 59 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 60 | 61 | Author: Tiago Balabuch 62 | 63 | ## RELATED LINKS 64 | 65 | {{ Fill in the related links here }} 66 | 67 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricDomainTenantSettingOverrides.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricDomainTenantSettingOverrides 10 | --- 11 | 12 | # Get-FabricDomainTenantSettingOverrides 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves tenant setting overrides for a specific domain or all capacities in the Fabric tenant. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricDomainTenantSettingOverrides [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Get-FabricDomainTenantSettingOverrides` function retrieves tenant setting overrides for all domains in the Fabric tenant by making a GET request to the designated API endpoint. 31 | The function ensures token validity before making the request and handles the response appropriately. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Fetches tenant setting overrides for all domains in the Fabric tenant. 38 | 39 | ```powershell 40 | Get-FabricDomainTenantSettingOverrides 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### CommonParameters 46 | 47 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 48 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 49 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 50 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 51 | 52 | ## INPUTS 53 | 54 | ## OUTPUTS 55 | 56 | ## NOTES 57 | 58 | - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. 59 | - Ensures token validity by invoking `Confirm-TokenState` before making the API request. 60 | - Logs detailed messages for debugging and error handling. 61 | 62 | Author: Tiago Balabuch 63 | 64 | ## RELATED LINKS 65 | 66 | {{ Fill in the related links here }} 67 | 68 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | ## Security 2 | 3 | We take the security of our modules seriously, which includes all source 4 | code repositories managed through our GitHub organization. 5 | 6 | If you believe you have found a security vulnerability in any of our 7 | repository, please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | If the repository has enabled the ability to report a security vulnerability 12 | through GitHub new issue (separate button called "Report a vulnerability") 13 | then use that. See [Privately reporting a security vulnerability](https://docs.github.com/en/code-security/security-advisories/guidance-on-reporting-and-writing-information-about-vulnerabilities/privately-reporting-a-security-vulnerability) 14 | for more information. 15 | 16 | > [!CAUTION] 17 | > Please do not report security vulnerabilities through a **public** GitHub issues 18 | > or other public forum. 19 | 20 | If the repository does not have that option then please 21 | report the security issue privately to one or several maintainers of the 22 | repository. The easiest way to do so is to send us a direct message via 23 | Twitter (X), Slack, Discord, or find us on some other social platform. 24 | 25 | You should receive a response within 48 hours. If for some reason you do not, 26 | please follow up by other means or to other contributors. 27 | 28 | Please include the requested information listed below (as much as you can 29 | provide) to help us better understand the nature and scope of the possible issue: 30 | 31 | * Type of issue 32 | * Full paths of source file(s) related to the manifestation of the issue 33 | * The location of the affected source code (tag/branch/commit or direct URL) 34 | * Any special configuration required to reproduce the issue 35 | * Step-by-step instructions to reproduce the issue 36 | * Proof-of-concept or exploit code (if possible) 37 | * Impact of the issue, including how an attacker might exploit the issue 38 | 39 | This information will help us triage your report more quickly. 40 | 41 | ## Preferred Languages 42 | 43 | We prefer all communications to be in English. 44 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricDomainWorkspace.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricDomainWorkspace 10 | --- 11 | 12 | # Get-FabricDomainWorkspace 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the workspaces associated with a specific domain in Microsoft Fabric. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricDomainWorkspace [-DomainId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Get-FabricDomainWorkspace` function fetches the workspaces for the given domain ID. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | Fetches workspaces for the domain with ID "12345". 37 | 38 | ```powershell 39 | Get-FabricDomainWorkspace -DomainId "12345" 40 | ``` 41 | 42 | ## PARAMETERS 43 | 44 | ### -DomainId 45 | 46 | The ID of the domain for which to retrieve workspaces. 47 | 48 | ```yaml 49 | Type: System.Guid 50 | DefaultValue: '' 51 | SupportsWildcards: false 52 | Aliases: [] 53 | ParameterSets: 54 | - Name: (All) 55 | Position: 0 56 | IsRequired: true 57 | ValueFromPipeline: false 58 | ValueFromPipelineByPropertyName: false 59 | ValueFromRemainingArguments: false 60 | DontShow: false 61 | AcceptedValues: [] 62 | HelpMessage: '' 63 | ``` 64 | 65 | ### CommonParameters 66 | 67 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 68 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 69 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 70 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ## OUTPUTS 75 | 76 | ## NOTES 77 | 78 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 79 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 80 | 81 | Author: Tiago Balabuch 82 | 83 | ## RELATED LINKS 84 | 85 | {{ Fill in the related links here }} 86 | 87 | -------------------------------------------------------------------------------- /docs/en-US/Add-FabricWorkspaceIdentity.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Add-FabricWorkspaceIdentity 10 | --- 11 | 12 | # Add-FabricWorkspaceIdentity 13 | 14 | ## SYNOPSIS 15 | 16 | Provisions an identity for a Fabric workspace. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Add-FabricWorkspaceIdentity [-WorkspaceId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Add-FabricWorkspaceIdentity` function provisions an identity for a specified workspace by making an API call. 31 | 32 | ## EXAMPLES 33 | 34 | ### EXAMPLE 1 35 | 36 | Provisions a Managed Identity for the workspace with ID "workspace123". 37 | 38 | ```powershell 39 | Add-FabricWorkspaceIdentity -WorkspaceId "workspace123" 40 | ``` 41 | 42 | ## PARAMETERS 43 | 44 | ### -WorkspaceId 45 | 46 | The unique identifier of the workspace for which the identity will be provisioned. 47 | 48 | ```yaml 49 | Type: System.Guid 50 | DefaultValue: '' 51 | SupportsWildcards: false 52 | Aliases: [] 53 | ParameterSets: 54 | - Name: (All) 55 | Position: 0 56 | IsRequired: true 57 | ValueFromPipeline: false 58 | ValueFromPipelineByPropertyName: false 59 | ValueFromRemainingArguments: false 60 | DontShow: false 61 | AcceptedValues: [] 62 | HelpMessage: '' 63 | ``` 64 | 65 | ### CommonParameters 66 | 67 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 68 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 69 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 70 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 71 | 72 | ## INPUTS 73 | 74 | ## OUTPUTS 75 | 76 | ## NOTES 77 | 78 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 79 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 80 | 81 | Author: Tiago Balabuch 82 | 83 | ## RELATED LINKS 84 | 85 | {{ Fill in the related links here }} 86 | 87 | -------------------------------------------------------------------------------- /source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineRoleAssignments.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDeploymentPipelineRoleAssignments { 2 | <# 3 | .SYNOPSIS 4 | Returns a list of deployment pipeline role assignments. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricDeploymentPipelineRoleAssignments` function retrieves a list of role assignments for a deployment pipeline. 8 | The function automatically handles pagination and returns all available role assignments. 9 | 10 | .PARAMETER DeploymentPipelineId 11 | Required. The ID of the deployment pipeline to get role assignments for. 12 | 13 | .EXAMPLE 14 | Returns all role assignments for the specified deployment pipeline. 15 | 16 | ```powershell 17 | Get-FabricDeploymentPipelineRoleAssignments -DeploymentPipelineId "GUID-GUID-GUID-GUID" 18 | ``` 19 | 20 | .NOTES 21 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 22 | - Requires Pipeline.Read.All or Pipeline.ReadWrite.All delegated scope. 23 | - Requires admin deployment pipelines role. 24 | - This API is in preview. 25 | 26 | Author: Kamil Nowinski 27 | #> 28 | [CmdletBinding()] 29 | param( 30 | [Parameter(Mandatory = $true)] 31 | [ValidateNotNullOrEmpty()] 32 | [Guid]$DeploymentPipelineId 33 | ) 34 | 35 | try { 36 | # Step 1: Ensure token validity 37 | Confirm-TokenState 38 | 39 | # Step 3: Construct the API URL 40 | $apiEndpointUrl = "deploymentPipelines/$DeploymentPipelineId/roleAssignments" 41 | 42 | # Step 4: Make the API request and validate response 43 | $apiParameters = @{ 44 | Uri = $apiEndpointUrl 45 | Method = 'GET' 46 | HandleResponse = $true 47 | TypeName = "deployment pipeline role assignments" 48 | ObjectIdOrName = $DeploymentPipelineId 49 | } 50 | $response = Invoke-FabricRestMethod @apiParameters 51 | 52 | # Step 7: Return results 53 | $response 54 | 55 | } catch { 56 | # Step 8: Error handling 57 | $errorDetails = $_.Exception.Message 58 | Write-Error -Message "Failed to get deployment pipeline role assignments. Error: $errorDetails" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricConnection.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricConnection 10 | --- 11 | 12 | # Get-FabricConnection 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves Fabric connections. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricConnection [[-connectionId] ] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The Get-FabricConnection function retrieves Fabric connections. 31 | It can retrieve all connections or the specified one only. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Get-FabricConnection 38 | 39 | This example retrieves all connections from Fabric 40 | 41 | ### EXAMPLE 2 42 | 43 | Get-FabricConnection -connectionId "12345" 44 | 45 | This example retrieves specific connection from Fabric with ID "12345". 46 | 47 | ## PARAMETERS 48 | 49 | ### -connectionId 50 | 51 | The ID of the connection to retrieve. 52 | 53 | ```yaml 54 | Type: System.Guid 55 | DefaultValue: '' 56 | SupportsWildcards: false 57 | Aliases: [] 58 | ParameterSets: 59 | - Name: (All) 60 | Position: 0 61 | IsRequired: false 62 | ValueFromPipeline: false 63 | ValueFromPipelineByPropertyName: false 64 | ValueFromRemainingArguments: false 65 | DontShow: false 66 | AcceptedValues: [] 67 | HelpMessage: '' 68 | ``` 69 | 70 | ### CommonParameters 71 | 72 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 73 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 74 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 75 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 76 | 77 | ## INPUTS 78 | 79 | ## OUTPUTS 80 | 81 | ## NOTES 82 | 83 | https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/get-connection?tabs=HTTP 84 | https://learn.microsoft.com/en-us/rest/api/fabric/core/connections/list-connections?tabs=HTTP 85 | 86 | Author: Kamil Nowinski 87 | 88 | ## RELATED LINKS 89 | 90 | {{ Fill in the related links here }} 91 | 92 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricDashboard.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricDashboard 10 | --- 11 | 12 | # Get-FabricDashboard 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves dashboards from a specified workspace. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricDashboard [-WorkspaceId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | This function retrieves all dashboards from a specified workspace using the provided WorkspaceId. 31 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | This example retrieves all dashboards from the workspace with ID "12345". 38 | 39 | ```powershell 40 | Get-FabricDashboard -WorkspaceId "12345" 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### -WorkspaceId 46 | 47 | The ID of the workspace from which to retrieve dashboards. 48 | This parameter is mandatory. 49 | 50 | ```yaml 51 | Type: System.Guid 52 | DefaultValue: '' 53 | SupportsWildcards: false 54 | Aliases: [] 55 | ParameterSets: 56 | - Name: (All) 57 | Position: 0 58 | IsRequired: true 59 | ValueFromPipeline: false 60 | ValueFromPipelineByPropertyName: false 61 | ValueFromRemainingArguments: false 62 | DontShow: false 63 | AcceptedValues: [] 64 | HelpMessage: '' 65 | ``` 66 | 67 | ### CommonParameters 68 | 69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 70 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 71 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 72 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 73 | 74 | ## INPUTS 75 | 76 | ## OUTPUTS 77 | 78 | ## NOTES 79 | 80 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 81 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 82 | 83 | Author: Tiago Balabuch 84 | 85 | ## RELATED LINKS 86 | 87 | {{ Fill in the related links here }} 88 | 89 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricContinuationToken.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricContinuationToken' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | } 13 | 14 | Describe "Get-FabricContinuationToken" -Tag "UnitTests" { 15 | 16 | Context "Command definition" { 17 | It 'Should have Response parameter' { 18 | InModuleScope -ModuleName 'FabricTools' { 19 | $command = Get-Command -Name Get-FabricContinuationToken 20 | $command | Should -HaveParameter -ParameterName 'Response' -Not -Mandatory 21 | } 22 | } 23 | } 24 | 25 | Context "When extracting continuation token" { 26 | It 'Should return continuation token from response' { 27 | InModuleScope -ModuleName 'FabricTools' { 28 | Mock -CommandName Write-Message -MockWith { } 29 | $mockResponse = [pscustomobject]@{ 30 | continuationToken = 'token123' 31 | } 32 | $result = Get-FabricContinuationToken -Response $mockResponse 33 | $result | Should -Be 'token123' 34 | } 35 | } 36 | 37 | It 'Should return null when no continuation token exists' { 38 | InModuleScope -ModuleName 'FabricTools' { 39 | Mock -CommandName Write-Message -MockWith { } 40 | $mockResponse = [pscustomobject]@{ 41 | data = 'somedata' 42 | } 43 | $result = Get-FabricContinuationToken -Response $mockResponse 44 | $result | Should -BeNullOrEmpty 45 | } 46 | } 47 | 48 | It 'Should return null when response is null' { 49 | InModuleScope -ModuleName 'FabricTools' { 50 | Mock -CommandName Write-Message -MockWith { } 51 | $result = Get-FabricContinuationToken -Response $null 52 | $result | Should -BeNullOrEmpty 53 | } 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /source/Public/Config/Set-FabricConfig.ps1: -------------------------------------------------------------------------------- 1 | function Set-FabricConfig { 2 | <# 3 | .SYNOPSIS 4 | Register the configuration for use with all functions in the FabricTools module. 5 | 6 | .DESCRIPTION 7 | Register the configuration for use with all functions in the FabricTools module. 8 | 9 | .PARAMETER WorkspaceGUID 10 | This is the workspace GUID in which the Data Warehouse resides. 11 | 12 | .PARAMETER DataWarehouseGUID 13 | The GUID for the Data Warehouse which we want to retrieve restore points for. 14 | 15 | .PARAMETER BaseUrl 16 | Defaults to api.powerbi.com 17 | 18 | .PARAMETER SkipPersist 19 | If set, the configuration will not be persisted to the registry. 20 | 21 | .EXAMPLE 22 | Registers the specified Fabric Data Warehouse configuration for use with all functions in the FabricTools module. 23 | 24 | ```powershell 25 | Set-FabricConfig -WorkspaceGUID 'GUID-GUID-GUID-GUID' -DataWarehouseGUID 'GUID-GUID-GUID-GUID' 26 | ``` 27 | 28 | .EXAMPLE 29 | Registers the specified Fabric Data Warehouse configuration for use with all functions in the FabricTools module, but does not persist the values. 30 | 31 | ```powershell 32 | Set-FabricConfig -WorkspaceGUID 'GUID-GUID-GUID-GUID' -DataWarehouseGUID 'GUID-GUID-GUID-GUID' -SkipPersist 33 | ``` 34 | 35 | .NOTES 36 | 37 | Author: Jess Pomfret 38 | #> 39 | [CmdletBinding(SupportsShouldProcess)] 40 | param ( 41 | [guid]$WorkspaceGUID, 42 | 43 | [guid]$DataWarehouseGUID, 44 | 45 | $BaseUrl = 'api.powerbi.com', 46 | 47 | [switch]$SkipPersist 48 | ) 49 | 50 | if ($PSCmdlet.ShouldProcess("Setting Fabric Configuration")) { 51 | 52 | if ($BaseUrl) { 53 | Set-PSFConfig -Module 'FabricTools' -Name BaseUrl -Value $BaseUrl 54 | } 55 | if ($WorkspaceGUID) { 56 | Set-PSFConfig -Module 'FabricTools' -Name WorkspaceGUID -Value $WorkspaceGUID 57 | } 58 | if ($DataWarehouseGUID) { 59 | Set-PSFConfig -Module 'FabricTools' -Name DataWarehouseGUID -Value $DataWarehouseGUID 60 | } 61 | 62 | # Register the config values in the registry if skip persist is not set 63 | if (-not $SkipPersist) { 64 | Register-PSFConfig -Module 'FabricTools' -Scope SystemMandatory 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /source/Public/Workspace/Unregister-FabricWorkspaceToCapacity.ps1: -------------------------------------------------------------------------------- 1 | function Unregister-FabricWorkspaceToCapacity { 2 | <# 3 | .SYNOPSIS 4 | Unregisters a workspace from a capacity. 5 | 6 | .DESCRIPTION 7 | The Unregister-FabricWorkspaceToCapacity function unregisters a workspace from a capacity in PowerBI. It can be used to remove a workspace from a capacity, allowing it to be assigned to a different capacity or remain unassigned. 8 | 9 | .PARAMETER WorkspaceId 10 | Specifies the ID of the workspace to be unregistered from the capacity. This parameter is mandatory when using the 'WorkspaceId' parameter set. 11 | 12 | .PARAMETER Workspace 13 | Specifies the workspace object to be unregistered from the capacity. This parameter is mandatory when using the 'WorkspaceObject' parameter set. The workspace object can be piped into the function. 14 | 15 | .EXAMPLE 16 | Unregisters the workspace with ID "12345678" from the capacity. 17 | 18 | ```powershell 19 | Unregister-FabricWorkspaceToCapacity -WorkspaceId "12345678" 20 | ``` 21 | 22 | .EXAMPLE 23 | Unregisters the workspace objects piped from Get-FabricWorkspace from the capacity. .INPUTS System.Management.Automation.PSCustomObject 24 | 25 | ```powershell 26 | Get-FabricWorkspace | Unregister-FabricWorkspaceToCapacity 27 | ``` 28 | 29 | .OUTPUTS 30 | System.Object 31 | 32 | .NOTES 33 | Author: Ioana Bouariu 34 | #> 35 | [Alias("Unregister-FabWorkspaceToCapacity")] 36 | [CmdletBinding(SupportsShouldProcess)] 37 | param( 38 | [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceId')] 39 | [guid]$WorkspaceId, 40 | 41 | [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceObject', ValueFromPipeline = $true)] 42 | $Workspace 43 | ) 44 | 45 | begin { 46 | Confirm-TokenState 47 | } 48 | 49 | Process { 50 | if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject') { 51 | $workspaceid = $workspace.id 52 | } 53 | 54 | if ($PSCmdlet.ShouldProcess("Unassigns workspace $workspaceid from a capacity")) { 55 | Invoke-FabricRestMethod -Uri "workspaces/$workspaceid/unassignFromCapacity" -Method POST 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricCapacityRefreshables.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricCapacityRefreshables 10 | --- 11 | 12 | # Get-FabricCapacityRefreshables 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the top refreshable capacities for the tenant. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricCapacityRefreshables [[-top] ] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | Get-FabCapacityRefreshables 29 | 30 | ## DESCRIPTION 31 | 32 | The Get-FabricCapacityRefreshables function retrieves the top refreshable capacities for the tenant. 33 | It supports multiple aliases for flexibility. 34 | 35 | ## EXAMPLES 36 | 37 | ### EXAMPLE 1 38 | 39 | This example retrieves the top 5 refreshable capacities for the tenant. 40 | 41 | ```powershell 42 | Get-FabricCapacityRefreshables -top 5 43 | ``` 44 | 45 | ## PARAMETERS 46 | 47 | ### -top 48 | 49 | The number of top refreshable capacities to retrieve. 50 | This is a mandatory parameter. 51 | 52 | ```yaml 53 | Type: System.String 54 | DefaultValue: 5 55 | SupportsWildcards: false 56 | Aliases: [] 57 | ParameterSets: 58 | - Name: (All) 59 | Position: 0 60 | IsRequired: false 61 | ValueFromPipeline: false 62 | ValueFromPipelineByPropertyName: false 63 | ValueFromRemainingArguments: false 64 | DontShow: false 65 | AcceptedValues: [] 66 | HelpMessage: '' 67 | ``` 68 | 69 | ### CommonParameters 70 | 71 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 72 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 73 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 74 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | 82 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the top refreshable capacities. 83 | It then returns the 'value' property of the response, which contains the capacities. 84 | 85 | Author: Ioana Bouariu 86 | 87 | ## RELATED LINKS 88 | 89 | {{ Fill in the related links here }} 90 | 91 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricCapacityWorkload.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricCapacityWorkload 10 | --- 11 | 12 | # Get-FabricCapacityWorkload 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the workloads for a specific capacity. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricCapacityWorkload [-CapacityId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | Get-FabCapacityWorkload 29 | 30 | ## DESCRIPTION 31 | 32 | The Get-FabricCapacityWorkload function retrieves the workloads for a specific capacity. 33 | It supports multiple aliases for flexibility. 34 | 35 | ## EXAMPLES 36 | 37 | ### EXAMPLE 1 38 | 39 | This example retrieves the workloads for a specific capacity given the capacity ID and authentication token. 40 | 41 | ```powershell 42 | Get-FabricCapacityWorkload -capacityID "your-capacity-id" 43 | ``` 44 | 45 | ## PARAMETERS 46 | 47 | ### -CapacityId 48 | 49 | The ID of the capacity. 50 | This is a mandatory parameter. 51 | 52 | ```yaml 53 | Type: System.Guid 54 | DefaultValue: '' 55 | SupportsWildcards: false 56 | Aliases: [] 57 | ParameterSets: 58 | - Name: (All) 59 | Position: 0 60 | IsRequired: true 61 | ValueFromPipeline: false 62 | ValueFromPipelineByPropertyName: false 63 | ValueFromRemainingArguments: false 64 | DontShow: false 65 | AcceptedValues: [] 66 | HelpMessage: '' 67 | ``` 68 | 69 | ### CommonParameters 70 | 71 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 72 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 73 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 74 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | 82 | The function retrieves the PowerBI access token and makes a GET request to the PowerBI API to retrieve the workloads for the specified capacity. 83 | It then returns the 'value' property of the response, which contains the workloads. 84 | 85 | Author: Ioana Bouariu 86 | 87 | ## RELATED LINKS 88 | 89 | {{ Fill in the related links here }} 90 | 91 | -------------------------------------------------------------------------------- /source/Public/Tenant/Get-FabricWorkspaceTenantSettingOverrides.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricWorkspaceTenantSettingOverrides { 2 | <# 3 | .SYNOPSIS 4 | Retrieves tenant setting overrides for all workspaces in the Fabric tenant. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricWorkspaceTenantSettingOverrides` function retrieves tenant setting overrides for all workspaces in the Fabric tenant by making a GET request to the appropriate API endpoint. The function validates the authentication token before making the request and handles the response accordingly. 8 | 9 | .EXAMPLE 10 | Returns all workspaces tenant setting overrides. 11 | 12 | ```powershell 13 | Get-FabricWorkspaceTenantSettingOverrides 14 | ``` 15 | 16 | .NOTES 17 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 18 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 19 | 20 | Author: Tiago Balabuch 21 | #> 22 | [CmdletBinding()] 23 | param ( ) 24 | 25 | try { 26 | # Step 1: Validate authentication token before making API requests 27 | Confirm-TokenState 28 | 29 | # Step 2: Construct the API endpoint URL for retrieving workspaces tenant setting overrides 30 | $apiEndpointURI = "admin/workspaces/delegatedTenantSettingOverrides" 31 | 32 | # Step 3: Invoke the Fabric API to retrieve workspaces tenant setting overrides 33 | $response = Invoke-FabricRestMethod ` 34 | -Uri $apiEndpointURI ` 35 | -Method Get 36 | 37 | # Step 4: Check if any workspaces tenant setting overrides were retrieved and handle results accordingly 38 | if ($response) { 39 | Write-Message -Message "Successfully retrieved workspaces tenant setting overrides." -Level Debug 40 | return $response 41 | } else { 42 | Write-Message -Message "No workspaces tenant setting overrides found." -Level Warning 43 | return $null 44 | } 45 | } catch { 46 | # Step 5: Log detailed error information if the API request fails 47 | $errorDetails = $_.Exception.Message 48 | Write-Message -Message "Error retrieving workspaces tenant setting overrides: $errorDetails" -Level Error 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /docs/en-US/Invoke-FabricDatasetRefresh.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Invoke-FabricDatasetRefresh 10 | --- 11 | 12 | # Invoke-FabricDatasetRefresh 13 | 14 | ## SYNOPSIS 15 | 16 | This function invokes a refresh of a PowerBI dataset 17 | 18 | ## SYNTAX 19 | 20 | ### DatasetId 21 | 22 | ``` 23 | Invoke-FabricDatasetRefresh -DatasetID [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | Invoke-FabDatasetRefresh 29 | 30 | ## DESCRIPTION 31 | 32 | The Invoke-FabricDatasetRefresh function is used to refresh a PowerBI dataset. 33 | It first checks if the dataset is refreshable. 34 | If it is not, it writes an error. 35 | If it is, it invokes a PowerBI REST method to refresh the dataset. 36 | The URL for the request is constructed using the provided dataset ID. 37 | 38 | ## EXAMPLES 39 | 40 | ### EXAMPLE 1 41 | 42 | Invoke-FabricDatasetRefresh -DatasetID "12345678-1234-1234-1234-123456789012" 43 | 44 | This command invokes a refresh of the dataset with the ID "12345678-1234-1234-1234-123456789012" 45 | 46 | ## PARAMETERS 47 | 48 | ### -DatasetID 49 | 50 | A mandatory parameter that specifies the dataset ID. 51 | 52 | ```yaml 53 | Type: System.Guid 54 | DefaultValue: '' 55 | SupportsWildcards: false 56 | Aliases: [] 57 | ParameterSets: 58 | - Name: DatasetId 59 | Position: Named 60 | IsRequired: true 61 | ValueFromPipeline: false 62 | ValueFromPipelineByPropertyName: false 63 | ValueFromRemainingArguments: false 64 | DontShow: false 65 | AcceptedValues: [] 66 | HelpMessage: '' 67 | ``` 68 | 69 | ### CommonParameters 70 | 71 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 72 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 73 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 74 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 75 | 76 | ## INPUTS 77 | 78 | ## OUTPUTS 79 | 80 | ## NOTES 81 | 82 | Alias: Invoke-FabDatasetRefresh 83 | 84 | Author: Ioana Bouariu 85 | 86 | 87 | Define aliases for the function for flexibility. 88 | 89 | ## RELATED LINKS 90 | 91 | {{ Fill in the related links here }} 92 | 93 | -------------------------------------------------------------------------------- /.github/workflows/publish-module.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - main 5 | paths-ignore: 6 | - CHANGELOG.md 7 | - .vscode/** 8 | - .github/** 9 | - images/** 10 | - tests/** 11 | - '**.md' 12 | - '**.yml' 13 | tags: 14 | - '*' 15 | env: 16 | buildFolderName: output 17 | buildArtifactName: output 18 | 19 | permissions: 20 | actions: write # to allow the workflow to run actions 21 | checks: write # to allow the workflow to create checks 22 | statuses: write # to allow the workflow to create statuses 23 | 24 | name: Deploy Module (only) 25 | # This workflow is triggered on push to the main branch and deploys the module to the PowerShell Gallery and creates a GitHub Release. 26 | jobs: 27 | Build_Stage_Package_Module: 28 | name: Package Module 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout Code 32 | uses: actions/checkout@v3 33 | with: 34 | ref: ${{ github.head_ref }} # checkout the triggered ref (branch or tag) 35 | fetch-depth: 0 36 | token: ${{ secrets.GITHUB_TOKEN }} 37 | - name: Build & Package Module 38 | shell: pwsh 39 | run: ./build.ps1 -ResolveDependency -tasks pack 40 | - name: Publish Build Artifact 41 | uses: actions/upload-artifact@v4 42 | with: 43 | name: ${{ env.buildArtifactName }} 44 | path: ${{ env.buildFolderName }}/ 45 | 46 | Deploy_Stage_Deploy_Module: 47 | name: Deploy Module 48 | runs-on: ubuntu-latest 49 | needs: 50 | - Build_Stage_Package_Module 51 | if: ${{ success() && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) }} 52 | steps: 53 | - name: Checkout Code 54 | uses: actions/checkout@v3 55 | with: 56 | ref: ${{ github.head_ref }} # checkout the triggered ref (branch or tag) 57 | fetch-depth: 0 58 | token: ${{ secrets.GITHUB_TOKEN }} 59 | - name: Download Build Artifact 60 | uses: actions/download-artifact@v4 61 | with: 62 | name: ${{ env.buildArtifactName }} 63 | path: ${{ env.buildFolderName }} 64 | - name: Publish Release 65 | shell: pwsh 66 | run: ./build.ps1 -tasks publish 67 | env: 68 | GitHubToken: ${{ secrets.GitHubToken }} 69 | GalleryApiToken: ${{ secrets.GalleryApiToken }} 70 | -------------------------------------------------------------------------------- /source/Public/Deployment Pipeline/Remove-FabricDeploymentPipeline.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricDeploymentPipeline { 2 | <# 3 | .SYNOPSIS 4 | Deletes a specified deployment pipeline. 5 | 6 | .DESCRIPTION 7 | The `Remove-FabricDeploymentPipeline` function deletes a deployment pipeline by its ID. 8 | This operation requires admin deployment pipelines role and will fail if there's an active deployment operation. 9 | 10 | .PARAMETER DeploymentPipelineId 11 | Required. The ID of the deployment pipeline to delete. 12 | 13 | .EXAMPLE 14 | Deletes the specified deployment pipeline. 15 | 16 | ```powershell 17 | Remove-FabricDeploymentPipeline -DeploymentPipelineId "GUID-GUID-GUID-GUID" 18 | ``` 19 | 20 | .NOTES 21 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 22 | - Requires Pipeline.ReadWrite.All delegated scope. 23 | - Requires admin deployment pipelines role. 24 | - Operation will fail if there's an active deployment operation. 25 | 26 | Author: Kamil Nowinski 27 | #> 28 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 29 | param( 30 | [Parameter(Mandatory = $true)] 31 | [ValidateNotNullOrEmpty()] 32 | [Guid]$DeploymentPipelineId 33 | ) 34 | 35 | try { 36 | # Step 1: Ensure token validity 37 | Confirm-TokenState 38 | 39 | # Step 2: Construct the API URL 40 | $apiEndpointUrl = "deploymentPipelines/$DeploymentPipelineId" 41 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 42 | 43 | # Step 3: Make the API request & validate response 44 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete Deployment Pipeline")) 45 | { 46 | $apiParameters = @{ 47 | Uri = $apiEndpointUrl 48 | Method = 'DELETE' 49 | HandleResponse = $true 50 | TypeName = "deployment pipeline" 51 | ObjectIdOrName = $DeploymentPipelineId 52 | } 53 | $response = Invoke-FabricRestMethod @apiParameters 54 | } 55 | 56 | # Step 4: Handle results 57 | $response 58 | 59 | } catch { 60 | # Step 5: Error handling 61 | $errorDetails = $_.Exception.Message 62 | Write-Error -Message "Failed to delete deployment pipeline. Error: $errorDetails" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /source/Public/Domain/Remove-FabricDomain.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricDomain 2 | { 3 | <# 4 | .SYNOPSIS 5 | Deletes a Fabric domain by its ID. 6 | 7 | .DESCRIPTION 8 | The `Remove-FabricDomain` function removes a specified domain from Microsoft Fabric by making a DELETE request to the relevant API endpoint. 9 | 10 | .PARAMETER DomainId 11 | The unique identifier of the domain to be deleted. 12 | 13 | .EXAMPLE 14 | Deletes the domain with ID "12345". 15 | 16 | ```powershell 17 | Remove-FabricDomain -DomainId "12345" 18 | ``` 19 | 20 | .NOTES 21 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 22 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 23 | 24 | Author: Tiago Balabuch 25 | 26 | #> 27 | [CmdletBinding(SupportsShouldProcess,ConfirmImpact = 'High')] 28 | param ( 29 | [Parameter(Mandatory = $true)] 30 | [ValidateNotNullOrEmpty()] 31 | [guid]$DomainId 32 | ) 33 | 34 | try 35 | { 36 | # Step 1: Ensure token validity 37 | Confirm-TokenState 38 | 39 | # Step 2: Construct the API URL 40 | $apiEndpointUrl = "{0}/admin/domains/{1}" -f $FabricConfig.BaseUrl, $DomainId 41 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 42 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Domain")) 43 | { 44 | # Step 3: Make the API request 45 | $response = Invoke-FabricRestMethod ` 46 | -Uri $apiEndpointUrl ` 47 | -Method Delete 48 | } 49 | 50 | # Step 4: Validate the response code 51 | if ($statusCode -ne 200) 52 | { 53 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 54 | Write-Message -Message "Error: $($response.message)" -Level Error 55 | Write-Message "Error Code: $($response.errorCode)" -Level Error 56 | return $null 57 | } 58 | 59 | Write-Message -Message "Domain '$DomainId' deleted successfully!" -Level Info 60 | 61 | } 62 | catch 63 | { 64 | # Step 5: Log and handle errors 65 | $errorDetails = $_.Exception.Message 66 | Write-Message -Message "Failed to delete domain '$DomainId'. Error: $errorDetails" -Level Error 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /source/Public/Item/Get-FabricItem.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricItem { 2 | <# 3 | .SYNOPSIS 4 | Retrieves fabric items from a workspace. 5 | 6 | .DESCRIPTION 7 | The Get-FabricItem function retrieves fabric items from a specified workspace. It can retrieve all items or filter them by item type. 8 | 9 | .PARAMETER workspaceId 10 | The ID of the workspace from which to retrieve the fabric items. 11 | 12 | .PARAMETER Workspace 13 | The workspace object from which to retrieve the fabric items. This parameter can be piped into the function. 14 | 15 | .PARAMETER itemID 16 | The ID of the specific item to retrieve. If not specified, all items will be retrieved. 17 | 18 | .PARAMETER type 19 | (Optional) The type of the fabric items to retrieve. If not specified, all items will be retrieved. 20 | 21 | .EXAMPLE 22 | This example retrieves all fabric items of type "file" from the workspace with ID "12345". 23 | 24 | ```powershell 25 | Get-FabricItem -workspaceId "12345" -type "file" 26 | ``` 27 | 28 | .NOTES 29 | 30 | Author: Rui Romano 31 | 32 | #> 33 | [CmdletBinding()] 34 | param 35 | ( 36 | [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceId')] 37 | [guid]$WorkspaceId, 38 | 39 | [Parameter(Mandatory = $true, ParameterSetName = 'WorkspaceObject', ValueFromPipeline = $true )] 40 | $Workspace, 41 | 42 | [Parameter(Mandatory = $false)] 43 | [Alias("itemType")] 44 | [string]$type, 45 | 46 | [Parameter(Mandatory = $false)] 47 | [guid]$itemID 48 | ) 49 | 50 | begin { 51 | Confirm-TokenState 52 | } 53 | 54 | process { 55 | if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject') { 56 | $workspaceID = $Workspace.id 57 | } 58 | if ($itemID) { 59 | $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items/$($itemID)" -Method Get 60 | } else { 61 | if ($type) { 62 | $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items?type=$type" -Method Get 63 | } else { 64 | # Invoke the Fabric API to get the workspaces 65 | $result = Invoke-FabricRestMethod -Uri "workspaces/$($workspaceID)/items" -Method Get 66 | } 67 | # Output the result 68 | return $result.value 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /docs/en-US/Convert-FromBase64.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Convert-FromBase64 10 | --- 11 | 12 | # Convert-FromBase64 13 | 14 | ## SYNOPSIS 15 | 16 | Decodes a Base64-encoded string into its original text representation. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Convert-FromBase64 [-Base64String] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The Convert-FromBase64 function takes a Base64-encoded string as input, decodes it into a byte array, 31 | and converts it back into a UTF-8 encoded string. 32 | It is useful for reversing Base64 encoding applied 33 | to text or other data. 34 | 35 | ## EXAMPLES 36 | 37 | ### EXAMPLE 1 38 | 39 | Output: Hello, World! 40 | 41 | ```powershell 42 | Convert-FromBase64 -Base64String "SGVsbG8sIFdvcmxkIQ==" 43 | ``` 44 | 45 | ### EXAMPLE 2 46 | 47 | Output: Some encoded text 48 | 49 | ```powershell 50 | $encodedString = "U29tZSBlbmNvZGVkIHRleHQ=" 51 | Convert-FromBase64 -Base64String $encodedString 52 | ``` 53 | 54 | ## PARAMETERS 55 | 56 | ### -Base64String 57 | 58 | The Base64-encoded string that you want to decode. 59 | 60 | ```yaml 61 | Type: System.String 62 | DefaultValue: '' 63 | SupportsWildcards: false 64 | Aliases: [] 65 | ParameterSets: 66 | - Name: (All) 67 | Position: 0 68 | IsRequired: true 69 | ValueFromPipeline: false 70 | ValueFromPipelineByPropertyName: false 71 | ValueFromRemainingArguments: false 72 | DontShow: false 73 | AcceptedValues: [] 74 | HelpMessage: '' 75 | ``` 76 | 77 | ### CommonParameters 78 | 79 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 80 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 81 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 82 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 83 | 84 | ## INPUTS 85 | 86 | ## OUTPUTS 87 | 88 | ## NOTES 89 | 90 | This function assumes the Base64 input is a valid UTF-8 encoded string. 91 | Any decoding errors will throw a descriptive error message. 92 | 93 | Author: Tiago Balabuch 94 | 95 | ## RELATED LINKS 96 | 97 | {{ Fill in the related links here }} 98 | 99 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricConfig.tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricConfig' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricConfig 14 | } 15 | 16 | Describe "Get-FabricConfig" -Tag 'UnitTests' { 17 | 18 | Context "Command definition" { 19 | It 'Should have ConfigName parameter' { 20 | $Command | Should -HaveParameter 'ConfigName' -Type [string] 21 | } 22 | 23 | It 'ConfigName parameter should not be mandatory' { 24 | $Command | Should -HaveParameter 'ConfigName' -Not -Mandatory 25 | } 26 | } 27 | 28 | Context "Get all configuration" { 29 | BeforeAll { 30 | Mock -CommandName Get-PSFConfig -MockWith { 31 | return @( 32 | [pscustomobject]@{ Name = 'BaseUrl'; Value = 'https://api.fabric.microsoft.com/v1' } 33 | [pscustomobject]@{ Name = 'Timeout'; Value = 300 } 34 | ) 35 | } 36 | } 37 | 38 | It 'Should return all config when no ConfigName specified' { 39 | $result = Get-FabricConfig 40 | $result | Should -Not -BeNullOrEmpty 41 | 42 | Should -Invoke -CommandName Get-PSFConfig -ParameterFilter { 43 | $Module -eq 'FabricTools' -and $null -eq $Name 44 | } -Times 1 -Exactly 45 | } 46 | } 47 | 48 | Context "Get specific configuration" { 49 | BeforeAll { 50 | Mock -CommandName Get-PSFConfig -MockWith { 51 | return [pscustomobject]@{ Name = 'BaseUrl'; Value = 'https://api.fabric.microsoft.com/v1' } 52 | } 53 | } 54 | 55 | It 'Should return specific config when ConfigName is specified' { 56 | $result = Get-FabricConfig -ConfigName 'BaseUrl' 57 | $result | Should -Not -BeNullOrEmpty 58 | 59 | Should -Invoke -CommandName Get-PSFConfig -ParameterFilter { 60 | $Module -eq 'FabricTools' -and $Name -eq 'BaseUrl' 61 | } -Times 1 -Exactly 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricTenantSetting.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricTenantSetting 10 | --- 11 | 12 | # Get-FabricTenantSetting 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves tenant settings from the Fabric environment. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricTenantSetting [[-SettingTitle] ] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Get-FabricTenantSetting` function retrieves tenant settings for a Fabric environment by making a GET request to the appropriate API endpoint. 31 | Optionally, it filters the results by the `SettingTitle` parameter. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Returns all tenant settings. 38 | 39 | ```powershell 40 | Get-FabricTenantSetting 41 | ``` 42 | 43 | ### EXAMPLE 2 44 | 45 | Returns the tenant setting with the title "SomeSetting". 46 | 47 | ```powershell 48 | Get-FabricTenantSetting -SettingTitle "SomeSetting" 49 | ``` 50 | 51 | ## PARAMETERS 52 | 53 | ### -SettingTitle 54 | 55 | (Optional) The title of a specific tenant setting to filter the results. 56 | 57 | ```yaml 58 | Type: System.String 59 | DefaultValue: '' 60 | SupportsWildcards: false 61 | Aliases: [] 62 | ParameterSets: 63 | - Name: (All) 64 | Position: 0 65 | IsRequired: false 66 | ValueFromPipeline: false 67 | ValueFromPipelineByPropertyName: false 68 | ValueFromRemainingArguments: false 69 | DontShow: false 70 | AcceptedValues: [] 71 | HelpMessage: '' 72 | ``` 73 | 74 | ### CommonParameters 75 | 76 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 77 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 78 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 79 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 80 | 81 | ## INPUTS 82 | 83 | ## OUTPUTS 84 | 85 | ## NOTES 86 | 87 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 88 | - Calls `Is-TokenExpired` to ensure token validity before making the API request. 89 | 90 | Author: Tiago Balabuch 91 | 92 | ## RELATED LINKS 93 | 94 | {{ Fill in the related links here }} 95 | 96 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricSparkSettings.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricSparkSettings 10 | --- 11 | 12 | # Get-FabricSparkSettings 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves Spark settings from a specified Microsoft Fabric workspace. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricSparkSettings [-WorkspaceId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | This function retrieves Spark settings from a specified workspace using the provided WorkspaceId. 31 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | This example retrieves the Spark settings for the workspace with ID "workspace-12345". 38 | 39 | ```powershell 40 | Get-FabricSparkSettings -WorkspaceId "workspace-12345" 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### -WorkspaceId 46 | 47 | The unique identifier of the workspace from which to retrieve Spark settings. 48 | This parameter is mandatory. 49 | 50 | ```yaml 51 | Type: System.Guid 52 | DefaultValue: '' 53 | SupportsWildcards: false 54 | Aliases: [] 55 | ParameterSets: 56 | - Name: (All) 57 | Position: 0 58 | IsRequired: true 59 | ValueFromPipeline: false 60 | ValueFromPipelineByPropertyName: false 61 | ValueFromRemainingArguments: false 62 | DontShow: false 63 | AcceptedValues: [] 64 | HelpMessage: '' 65 | ``` 66 | 67 | ### CommonParameters 68 | 69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 70 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 71 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 72 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 73 | 74 | ## INPUTS 75 | 76 | ## OUTPUTS 77 | 78 | ### System.Object 79 | 80 | {{ Fill in the Description }} 81 | 82 | ## NOTES 83 | 84 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 85 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 86 | 87 | Author: Tiago Balabuch 88 | 89 | ## RELATED LINKS 90 | 91 | {{ Fill in the related links here }} 92 | 93 | -------------------------------------------------------------------------------- /source/Public/Workspace/Get-FabricWorkspaceDatasetRefreshes.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricWorkspaceDatasetRefreshes { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the refresh history of all datasets in a specified PowerBI workspace. 5 | 6 | .DESCRIPTION 7 | The Get-FabricWorkspaceDatasetRefreshes function uses the PowerBI cmdlets to retrieve the refresh history of all datasets in a specified workspace. 8 | It uses the workspace ID to get the workspace and its datasets, and then retrieves the refresh history for each dataset. 9 | 10 | .PARAMETER WorkspaceID 11 | The ID of the PowerBI workspace. This is a mandatory parameter. 12 | 13 | .EXAMPLE 14 | This command retrieves the refresh history of all datasets in the workspace with the specified ID. .INPUTS String. You can pipe a string that contains the workspace ID to Get-FabricWorkspaceDatasetRefreshes. 15 | 16 | ```powershell 17 | Get-FabricWorkspaceDatasetRefreshes -WorkspaceID "12345678-90ab-cdef-1234-567890abcdef" 18 | ``` 19 | .INPUTS 20 | Guid. You can pipe a string that contains the workspace ID to Get-FabricWorkspaceDatasetRefreshes. 21 | 22 | .OUTPUTS 23 | Array. Get-FabricWorkspaceDatasetRefreshes returns an array of refresh history objects. 24 | 25 | .NOTES 26 | Alias: Get-FabWorkspaceDatasetRefreshes 27 | 28 | Author: Ioana Bouariu 29 | #> 30 | 31 | # Define a function to get the refresh history of all datasets in a PowerBI workspace 32 | # Set aliases for the function 33 | [Alias("Get-FabWorkspaceDatasetRefreshes")] 34 | param( 35 | # Define a mandatory parameter for the workspace ID 36 | [Parameter(Mandatory = $true)] 37 | [guid]$WorkspaceID 38 | ) 39 | 40 | Confirm-TokenState 41 | 42 | # Get the workspace using the workspace ID 43 | $wsp = Get-FabricWorkspace -workspaceid $WorkspaceID 44 | # Initialize an array to store the refresh history 45 | $refs = @() 46 | # Get all datasets in the workspace 47 | $datasets = Get-FabricDataset -workspaceid $wsp.Id 48 | 49 | # Loop over each dataset 50 | foreach ($dataset in $datasets) { 51 | # Get the refresh history of the dataset and add it to the array 52 | $refs += Get-FabricDatasetRefreshes -datasetid $dataset.Id -workspaceId $wsp.Id 53 | } 54 | # Return the refresh history array 55 | return $refs 56 | } 57 | -------------------------------------------------------------------------------- /source/Public/Copy Job/Remove-FabricCopyJob.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricCopyJob { 2 | <# 3 | .SYNOPSIS 4 | Deletes a Copy Job from a specified Microsoft Fabric workspace. 5 | 6 | .DESCRIPTION 7 | This function performs a DELETE operation on the Microsoft Fabric API to remove a Copy Job 8 | from the specified workspace using the provided WorkspaceId and CopyJobId parameters. 9 | 10 | .PARAMETER WorkspaceId 11 | The unique identifier of the workspace containing the Copy Job to be deleted. 12 | 13 | .PARAMETER CopyJobId 14 | The unique identifier of the Copy Job to delete. 15 | 16 | .EXAMPLE 17 | Deletes the Copy Job with ID "copyjob-67890" from the workspace with ID "workspace-12345". 18 | 19 | ```powershell 20 | Remove-FabricCopyJob -WorkspaceId "workspace-12345" -CopyJobId "copyjob-67890" 21 | ``` 22 | 23 | .NOTES 24 | - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. 25 | - Ensures token validity by invoking `Confirm-TokenState` before making the API request. 26 | 27 | Author: Tiago Balabuch 28 | #> 29 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 30 | param ( 31 | [Parameter(Mandatory = $true)] 32 | [ValidateNotNullOrEmpty()] 33 | [guid]$WorkspaceId, 34 | 35 | [Parameter(Mandatory = $true)] 36 | [ValidateNotNullOrEmpty()] 37 | [guid]$CopyJobId 38 | ) 39 | try { 40 | # Ensure token validity 41 | Confirm-TokenState 42 | 43 | # Construct the API endpoint URI 44 | $apiEndpointURI = "workspaces/{0}/copyJobs/{1}" -f $WorkspaceId, $CopyJobId 45 | Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug 46 | 47 | if($PSCmdlet.ShouldProcess($apiEndpointURI, "Delete Copy Job")) { 48 | 49 | # Make the API request 50 | $apiParams = @{ 51 | Uri = $apiEndpointURI 52 | Method = 'DELETE' 53 | } 54 | $response = Invoke-FabricRestMethod @apiParams 55 | } 56 | Write-Message -Message "Copy Job '$CopyJobId' deleted successfully from workspace '$WorkspaceId'." -Level Info 57 | return $response 58 | 59 | } catch { 60 | # Log and handle errors 61 | $errorDetails = $_.Exception.Message 62 | Write-Message -Message "Failed to delete Copy Job '$CopyJobId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /source/Public/Utils/Get-FabricLongRunningOperationResult.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricLongRunningOperationResult { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the result of a completed long-running operation from the Microsoft Fabric API. 5 | 6 | .DESCRIPTION 7 | The Get-FabricLongRunningOperationResult function queries the Microsoft Fabric API to fetch the result 8 | of a specific long-running operation. This is typically used after confirming the operation has completed successfully. 9 | 10 | .PARAMETER operationId 11 | The unique identifier of the completed long-running operation whose result you want to retrieve. 12 | 13 | .EXAMPLE 14 | This command fetches the result of the operation with the specified operationId. ```powershell ``` 15 | 16 | ```powershell 17 | Get-FabricLongRunningOperationResult -operationId "12345-abcd-67890-efgh" 18 | ``` 19 | 20 | .NOTES 21 | - This function does not handle polling. Ensure the operation is in a terminal state before calling this function. 22 | 23 | Author: Tiago Balabuch 24 | 25 | #> 26 | param ( 27 | [Parameter(Mandatory = $true)] 28 | [guid]$OperationId 29 | ) 30 | 31 | Write-Message -Message "[Get-FabricLongRunningOperationResult]::Begin" -Level Debug 32 | Confirm-TokenState 33 | 34 | # Step 1: Construct the API URL 35 | $apiEndpointUrl = "{0}/operations/{1}/result" -f $FabricConfig.BaseUrl, $OperationId 36 | Write-Message -Message "[Get-FabricLongRunningOperationResult] API Endpoint: $apiEndpointUrl" -Level Debug 37 | 38 | try { 39 | # Step 2: Make the API request 40 | $response = Invoke-FabricRestMethod -Uri $apiEndpointUrl -Method Get 41 | 42 | # Step 3: Validate the response code 43 | if ($script:statusCode -ne 200) { 44 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Debug 45 | Write-Message -Message "Error: $($response.message)" -Level Debug 46 | Write-Message -Message "Error Details: $($response.moreDetails)" -Level Debug 47 | Write-Message "Error Code: $($response.errorCode)" -Level Debug 48 | } 49 | 50 | return $response 51 | 52 | } catch { 53 | # Step 3: Capture and log error details 54 | $errorDetails = $_.Exception.Message 55 | Write-Message -Message "An error occurred while returning the operation result: $errorDetails" -Level Error 56 | throw 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /source/Public/Workspace/New-FabricWorkspaceUsageMetricsReport.ps1: -------------------------------------------------------------------------------- 1 | function New-FabricWorkspaceUsageMetricsReport { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the workspace usage metrics dataset ID. 5 | 6 | .DESCRIPTION 7 | The New-FabricWorkspaceUsageMetricsReport function retrieves the workspace usage metrics dataset ID. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER workspaceId 10 | The ID of the workspace. This is a mandatory parameter. 11 | 12 | .EXAMPLE 13 | This example retrieves the workspace usage metrics dataset ID for a specific workspace given the workspace ID. 14 | 15 | ```powershell 16 | New-FabricWorkspaceUsageMetricsReport -workspaceId "your-workspace-id" 17 | ``` 18 | 19 | .NOTES 20 | The function retrieves the PowerBI access token and the Fabric API cluster URI. It then makes a GET request to the Fabric API to retrieve the workspace usage metrics dataset ID, parses the response and replaces certain keys to match the expected format, and returns the 'dbName' property of the first model in the response, which is the dataset ID. 21 | 22 | Author: Ioana Bouariu 23 | 24 | #> 25 | 26 | # Define aliases for the function for flexibility. 27 | [Alias("New-FabWorkspaceUsageMetricsReport")] 28 | [CmdletBinding(SupportsShouldProcess)] 29 | # Define a parameter for the workspace ID. 30 | param( 31 | [Parameter(Mandatory = $true)] 32 | [guid]$WorkspaceId 33 | ) 34 | 35 | Confirm-TokenState 36 | 37 | # Retrieve the Fabric API cluster URI. 38 | $url = Get-FabricAPIclusterURI 39 | 40 | # Make a GET request to the Fabric API to retrieve the workspace usage metrics dataset ID. 41 | if ($PSCmdlet.ShouldProcess("Workspace Usage Metrics Report", "Retrieve")) { 42 | $headerParams = Get-PSFConfigValue FabricTools.FabricSession.Headers 43 | $data = Invoke-WebRequest -Uri "$url/$workspaceId/usageMetricsReportV2?experience=power-bi" -Headers $headerParams -ErrorAction SilentlyContinue 44 | # Parse the response and replace certain keys to match the expected format. 45 | $response = $data.Content.ToString().Replace("nextRefreshTime", "NextRefreshTime").Replace("lastRefreshTime", "LastRefreshTime") | ConvertFrom-Json 46 | 47 | # Return the 'dbName' property of the first model in the response, which is the dataset ID. 48 | return $response.models[0].dbName 49 | } else { 50 | return $null 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /source/Private/Get-FileDefinitionParts.ps1: -------------------------------------------------------------------------------- 1 | function Get-FileDefinitionParts { 2 | [CmdletBinding()] 3 | param ( 4 | [Parameter(Mandatory = $true)] 5 | [ValidateNotNullOrEmpty()] 6 | [string]$sourceDirectory 7 | ) 8 | try { 9 | if (-Not (Test-Path $sourceDirectory)) { 10 | Write-Message -Message "The specified source directory does not exist: $sourceDirectory" -Level Error 11 | throw 12 | } 13 | 14 | # Get all files from the directory recursively 15 | Write-Message -Message "Get all files from the directory recursively" -Level Debug 16 | $fileList = Get-ChildItem -Path $sourceDirectory -File -Recurse 17 | 18 | # Initialize the output JSON object 19 | $jsonObject = @{ parts = @() } 20 | 21 | # Loop through the files to create parts dynamically 22 | Write-Message -Message "Loop through the files to create parts dynamically" -Level Debug 23 | foreach ($file in $fileList) { 24 | 25 | $relativePath = $file.FullName.Substring($sourceDirectory.Length + 1) -replace "\\", "/" 26 | Write-Message -Message "File found: $relativePath" -Level Debug 27 | Write-Message -Message "Starting encode to base64" -Level Debug 28 | 29 | $base64Content = Convert-ToBase64 -filePath $file.FullName 30 | Write-Message -Message "Adding part to json object" -Level Debug 31 | 32 | $jsonObject.parts += @{ 33 | path = $relativePath 34 | payload = $base64Content 35 | payloadType = "InlineBase64" 36 | } 37 | } 38 | Write-Message -Message "Loop through the files finished" -Level Debug 39 | 40 | return $jsonObject 41 | Write-Message -Message "Parts returned" -Level Debug 42 | } 43 | 44 | catch { 45 | # Step 4: Handle and log errors 46 | $errorDetails = $_.Exception.Message 47 | Write-Message -Message "An error occurred while getting file definition parts: $errorDetails" -Level Error 48 | throw "An error occurred while encoding to Base64: $_" 49 | } 50 | } 51 | 52 | 53 | # Example usage 54 | #$sourceDirectory = "C:\temp\API\Notebook" 55 | #Get-FileParts -sourceDirectory $sourceDirectory 56 | #$fileParts = Get-FileParts -sourceDirectory $sourceDirectory 57 | #$fileParts | ConvertTo-Json -Depth 10 58 | -------------------------------------------------------------------------------- /source/Public/SQL Database/Remove-FabricSQLDatabase.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricSQLDatabase 2 | { 3 | <# 4 | .SYNOPSIS 5 | Deletes a SQL Database from a specified workspace in Microsoft Fabric. 6 | 7 | .DESCRIPTION 8 | The `Remove-FabricSQLDatabase` function sends a DELETE request to the Fabric API to remove a specified SQLDatabase from a given workspace. 9 | 10 | .PARAMETER WorkspaceId 11 | (Mandatory) The ID of the workspace containing the SQLDatabase to delete. 12 | 13 | .PARAMETER SQLDatabaseId 14 | (Mandatory) The ID of the SQL Database to be deleted. 15 | 16 | .EXAMPLE 17 | Deletes the SQL Database with ID "67890" from workspace "12345". 18 | 19 | ```powershell 20 | Remove-FabricSQLDatabas -WorkspaceId "12345" -SQLDatabaseId "67890" 21 | ``` 22 | 23 | .NOTES 24 | - Validates token expiration before making the API request. 25 | 26 | Author: Kamil Nowinski 27 | #> 28 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 29 | param ( 30 | [Parameter(Mandatory = $true)] 31 | [ValidateNotNullOrEmpty()] 32 | [guid]$WorkspaceId, 33 | 34 | [Parameter(Mandatory = $true)] 35 | [ValidateNotNullOrEmpty()] 36 | [guid]$SQLDatabaseId 37 | ) 38 | 39 | try 40 | { 41 | # Step 1: Ensure token validity 42 | Confirm-TokenState 43 | 44 | # Step 2: Construct the API URL 45 | $apiEndpointUrl = "workspaces/{0}/sqldatabases/{1}" -f $WorkspaceId, $SQLDatabaseId 46 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 47 | 48 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete SQL Database")) 49 | { 50 | # Step 3: Make the API request 51 | $apiParams = @{ 52 | Uri = $apiEndpointUrl 53 | Method = 'DELETE' 54 | TypeName = 'SQL Database' 55 | ObjectIdOrName = $SQLDatabaseId 56 | HandleResponse = $true 57 | } 58 | $response = Invoke-FabricRestMethod @apiParams 59 | $response 60 | } 61 | 62 | } 63 | catch 64 | { 65 | # Step 5: Log and handle errors 66 | $errorDetails = $_.Exception.Message 67 | Write-Message -Message "Failed to delete SQL Database '$SQLDatabaseId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /source/Public/Capacity/Get-FabricCapacityState.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricCapacityState { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the state of a specific capacity. 5 | 6 | .DESCRIPTION 7 | The Get-FabricCapacityState function retrieves the state of a specific capacity. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER SubscriptionID 10 | The ID of the subscription. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 11 | 12 | .PARAMETER ResourceGroup 13 | The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 14 | 15 | .PARAMETER Capacity 16 | The capacity. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 17 | 18 | .EXAMPLE 19 | This example retrieves the state of a specific capacity given the subscription ID, resource group, and capacity. 20 | 21 | ```powershell 22 | Get-FabricCapacityState -SubscriptionID "your-subscription-id" -ResourceGroup "your-resource-group" -Capacity "your-capacity" 23 | ``` 24 | 25 | .NOTES 26 | The function checks if the Azure token is null. If it is, it connects to the Azure account and retrieves the token. It then defines the headers for the GET request and the URL for the GET request. Finally, it makes the GET request and returns the response. 27 | 28 | Author: Ioana Bouariu 29 | 30 | #> 31 | 32 | # This function retrieves the state of a specific capacity. 33 | # Define aliases for the function for flexibility. 34 | [Alias("Get-FabCapacityState")] 35 | 36 | # Define mandatory parameters for the subscription ID, resource group, and capacity. 37 | Param ( 38 | [Parameter(Mandatory = $true)] 39 | [guid]$SubscriptionID, 40 | [Parameter(Mandatory = $true)] 41 | [string]$ResourceGroup, 42 | [Parameter(Mandatory = $true)] 43 | [string]$capacity 44 | ) 45 | 46 | Confirm-TokenState 47 | 48 | $AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl' 49 | $headers = Get-PSFConfigValue 'FabricTools.AzureSession.Headers' 50 | 51 | # Define the URL for the GET request. 52 | $getCapacityState = "$AzureBaseApiUrl/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Fabric/capacities/$Capacity/?api-version=2022-07-01-preview" 53 | 54 | # Make the GET request and return the response. 55 | return Invoke-RestMethod -Method GET -Uri $getCapacityState -Headers $headers -ErrorAction Stop 56 | } 57 | -------------------------------------------------------------------------------- /source/Public/Tenant/Get-FabricDomainTenantSettingOverrides.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDomainTenantSettingOverrides { 2 | <# 3 | .SYNOPSIS 4 | Retrieves tenant setting overrides for a specific domain or all capacities in the Fabric tenant. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricDomainTenantSettingOverrides` function retrieves tenant setting overrides for all domains in the Fabric tenant by making a GET request to the designated API endpoint. The function ensures token validity before making the request and handles the response appropriately. 8 | 9 | .EXAMPLE 10 | Fetches tenant setting overrides for all domains in the Fabric tenant. 11 | 12 | ```powershell 13 | Get-FabricDomainTenantSettingOverrides 14 | ``` 15 | 16 | .NOTES 17 | - Requires the `$FabricConfig` global configuration, which must include `BaseUrl` and `FabricHeaders`. 18 | - Ensures token validity by invoking `Confirm-TokenState` before making the API request. 19 | - Logs detailed messages for debugging and error handling. 20 | 21 | Author: Tiago Balabuch 22 | #> 23 | [CmdletBinding()] 24 | param ( ) 25 | 26 | try { 27 | # Step 1: Validate authentication token before making API requests 28 | Confirm-TokenState 29 | 30 | # Step 2: Construct the API endpoint URL for retrieving domain tenant setting overrides 31 | $apiEndpointURI = "admin/domains/delegatedTenantSettingOverrides" 32 | Write-Message -Message "Constructed API Endpoint: $apiEndpointURI" -Level Debug 33 | 34 | # Step 3: Invoke the Fabric API to retrieve domain tenant setting overrides 35 | $response = Invoke-FabricRestMethod ` 36 | -Uri $apiEndpointURI ` 37 | -Method Get 38 | 39 | # Step 4: Check if any domain tenant setting overrides were retrieved and handle results accordingly 40 | if ($response) { 41 | Write-Message -Message "Successfully retrieved domain tenant setting overrides." -Level Debug 42 | return $response 43 | } else { 44 | Write-Message -Message "No domain tenant setting overrides found." -Level Warning 45 | return $null 46 | } 47 | } catch { 48 | # Step 5: Log detailed error information if the API request fails 49 | $errorDetails = $_.Exception.Message 50 | Write-Message -Message "Error retrieving domain tenant setting overrides: $errorDetails" -Level Error 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricDeploymentPipelineRoleAssignments.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricDeploymentPipelineRoleAssignments 10 | --- 11 | 12 | # Get-FabricDeploymentPipelineRoleAssignments 13 | 14 | ## SYNOPSIS 15 | 16 | Returns a list of deployment pipeline role assignments. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricDeploymentPipelineRoleAssignments [-DeploymentPipelineId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The `Get-FabricDeploymentPipelineRoleAssignments` function retrieves a list of role assignments for a deployment pipeline. 31 | The function automatically handles pagination and returns all available role assignments. 32 | 33 | ## EXAMPLES 34 | 35 | ### EXAMPLE 1 36 | 37 | Returns all role assignments for the specified deployment pipeline. 38 | 39 | ```powershell 40 | Get-FabricDeploymentPipelineRoleAssignments -DeploymentPipelineId "GUID-GUID-GUID-GUID" 41 | ``` 42 | 43 | ## PARAMETERS 44 | 45 | ### -DeploymentPipelineId 46 | 47 | Required. 48 | The ID of the deployment pipeline to get role assignments for. 49 | 50 | ```yaml 51 | Type: System.Guid 52 | DefaultValue: '' 53 | SupportsWildcards: false 54 | Aliases: [] 55 | ParameterSets: 56 | - Name: (All) 57 | Position: 0 58 | IsRequired: true 59 | ValueFromPipeline: false 60 | ValueFromPipelineByPropertyName: false 61 | ValueFromRemainingArguments: false 62 | DontShow: false 63 | AcceptedValues: [] 64 | HelpMessage: '' 65 | ``` 66 | 67 | ### CommonParameters 68 | 69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 70 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 71 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 72 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 73 | 74 | ## INPUTS 75 | 76 | ## OUTPUTS 77 | 78 | ## NOTES 79 | 80 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 81 | - Requires Pipeline.Read.All or Pipeline.ReadWrite.All delegated scope. 82 | - Requires admin deployment pipelines role. 83 | - This API is in preview. 84 | 85 | Author: Kamil Nowinski 86 | 87 | ## RELATED LINKS 88 | 89 | {{ Fill in the related links here }} 90 | 91 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricWorkspaceTenantSettingOverrides.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricWorkspaceTenantSettingOverrides' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricWorkspaceTenantSettingOverrides 14 | } 15 | 16 | Describe "Get-FabricWorkspaceTenantSettingOverrides" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have no mandatory custom parameters' { 20 | # This command has no custom parameters, only common parameters 21 | $Command | Should -Not -BeNullOrEmpty 22 | } 23 | } 24 | 25 | Context "Successful tenant setting overrides retrieval" { 26 | BeforeAll { 27 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 28 | InModuleScope -ModuleName 'FabricTools' { 29 | $script:statusCode = 200 30 | } 31 | return [pscustomobject]@{ 32 | value = @( 33 | [pscustomobject]@{ settingName = 'setting-1'; enabled = $true } 34 | ) 35 | } 36 | } 37 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 38 | } 39 | 40 | It 'Should get workspace tenant setting overrides' { 41 | $result = Get-FabricWorkspaceTenantSettingOverrides 42 | 43 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 44 | } 45 | } 46 | 47 | Context "Error handling" { 48 | BeforeAll { 49 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 50 | throw "API Error" 51 | } 52 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 53 | Mock -CommandName Write-Message -MockWith { } 54 | } 55 | 56 | It 'Should handle errors gracefully' { 57 | { 58 | Get-FabricWorkspaceTenantSettingOverrides 59 | } | Should -Not -Throw 60 | 61 | Should -Invoke -CommandName Write-Message -ParameterFilter { 62 | $Level -eq 'Error' 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /docs/en-US/Get-FabricLongRunningOperationResult.md: -------------------------------------------------------------------------------- 1 | --- 2 | document type: cmdlet 3 | external help file: FabricTools-Help.xml 4 | HelpUri: '' 5 | Locale: en-US 6 | Module Name: FabricTools 7 | ms.date: 07/18/2025 8 | PlatyPS schema version: 2024-05-01 9 | title: Get-FabricLongRunningOperationResult 10 | --- 11 | 12 | # Get-FabricLongRunningOperationResult 13 | 14 | ## SYNOPSIS 15 | 16 | Retrieves the result of a completed long-running operation from the Microsoft Fabric API. 17 | 18 | ## SYNTAX 19 | 20 | ### __AllParameterSets 21 | 22 | ``` 23 | Get-FabricLongRunningOperationResult [-OperationId] [] 24 | ``` 25 | 26 | ## ALIASES 27 | 28 | ## DESCRIPTION 29 | 30 | The Get-FabricLongRunningOperationResult function queries the Microsoft Fabric API to fetch the result 31 | of a specific long-running operation. 32 | This is typically used after confirming the operation has completed successfully. 33 | 34 | ## EXAMPLES 35 | 36 | ### EXAMPLE 1 37 | 38 | This command fetches the result of the operation with the specified operationId. ```powershell ``` 39 | 40 | ```powershell 41 | Get-FabricLongRunningOperationResult -operationId "12345-abcd-67890-efgh" 42 | ``` 43 | 44 | ## PARAMETERS 45 | 46 | ### -OperationId 47 | 48 | The unique identifier of the completed long-running operation whose result you want to retrieve. 49 | 50 | ```yaml 51 | Type: System.Guid 52 | DefaultValue: '' 53 | SupportsWildcards: false 54 | Aliases: [] 55 | ParameterSets: 56 | - Name: (All) 57 | Position: 0 58 | IsRequired: true 59 | ValueFromPipeline: false 60 | ValueFromPipelineByPropertyName: false 61 | ValueFromRemainingArguments: false 62 | DontShow: false 63 | AcceptedValues: [] 64 | HelpMessage: '' 65 | ``` 66 | 67 | ### CommonParameters 68 | 69 | This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, 70 | -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, 71 | -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see 72 | [about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216). 73 | 74 | ## INPUTS 75 | 76 | ## OUTPUTS 77 | 78 | ## NOTES 79 | 80 | - Ensure the Fabric API headers (e.g., authorization tokens) are defined in $FabricConfig.FabricHeaders. 81 | - This function does not handle polling. 82 | Ensure the operation is in a terminal state before calling this function. 83 | 84 | Author: Tiago Balabuch 85 | 86 | ## RELATED LINKS 87 | 88 | {{ Fill in the related links here }} 89 | 90 | -------------------------------------------------------------------------------- /source/Public/Data Pipeline/Remove-FabricDataPipeline.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricDataPipeline 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes a DataPipeline from a specified Microsoft Fabric workspace. 6 | 7 | .DESCRIPTION 8 | This function sends a DELETE request to the Microsoft Fabric API to remove a DataPipeline 9 | from the specified workspace using the provided WorkspaceId and DataPipelineId. 10 | 11 | .PARAMETER WorkspaceId 12 | The unique identifier of the workspace from which the DataPipeline will be removed. 13 | 14 | .PARAMETER DataPipelineId 15 | The unique identifier of the DataPipeline to be removed. 16 | 17 | .EXAMPLE 18 | This example removes the DataPipeline with ID "pipeline-67890" from the workspace with ID "workspace-12345". 19 | 20 | ```powershell 21 | Remove-FabricDataPipeline -WorkspaceId "workspace-12345" -DataPipelineId "pipeline-67890" 22 | ``` 23 | 24 | .NOTES 25 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 26 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 27 | 28 | Author: Tiago Balabuch 29 | #> 30 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 31 | param ( 32 | [Parameter(Mandatory = $true)] 33 | [ValidateNotNullOrEmpty()] 34 | [guid]$WorkspaceId, 35 | 36 | [Parameter(Mandatory = $true)] 37 | [ValidateNotNullOrEmpty()] 38 | [guid]$DataPipelineId 39 | ) 40 | try 41 | { 42 | # Ensure token validity 43 | Confirm-TokenState 44 | 45 | # Construct the API URI 46 | $apiEndpointURI = "workspaces/{0}/dataPipelines/{1}" -f $WorkspaceId, $DataPipelineId 47 | Write-Message -Message "API Endpoint: $apiEndpointURI" -Level Debug 48 | 49 | if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Delete DataPipeline")) 50 | { 51 | # Make the API request 52 | $response = Invoke-FabricRestMethod ` 53 | -Uri $apiEndpointURI ` 54 | -Method Delete 55 | } 56 | Write-Message -Message "DataPipeline '$DataPipelineId' deleted successfully from workspace '$WorkspaceId'." -Level Info 57 | return $response 58 | } 59 | catch 60 | { 61 | # Log and handle errors 62 | $errorDetails = $_.Exception.Message 63 | Write-Message -Message "Failed to delete DataPipeline '$DataPipelineId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricExternalDataShares.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricExternalDataShares' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricExternalDataShares 14 | } 15 | 16 | Describe "Get-FabricExternalDataShares" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have no mandatory custom parameters' { 20 | # This command has no custom mandatory parameters, just common parameters 21 | $Command | Should -Not -BeNullOrEmpty 22 | } 23 | } 24 | 25 | Context "Successful external data shares retrieval" { 26 | BeforeAll { 27 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 28 | InModuleScope -ModuleName 'FabricTools' { 29 | $script:statusCode = 200 30 | } 31 | return [pscustomobject]@{ 32 | value = @( 33 | [pscustomobject]@{ id = 'share-guid'; name = 'TestShare' } 34 | ) 35 | } 36 | } 37 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 38 | } 39 | 40 | It 'Should return external data shares' { 41 | $result = Get-FabricExternalDataShares 42 | 43 | $result | Should -Not -BeNullOrEmpty 44 | 45 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 46 | } 47 | } 48 | 49 | Context "Error handling" { 50 | BeforeAll { 51 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 52 | throw "API Error" 53 | } 54 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 55 | Mock -CommandName Write-Message -MockWith { } 56 | } 57 | 58 | It 'Should handle errors gracefully' { 59 | { 60 | Get-FabricExternalDataShares 61 | } | Should -Not -Throw 62 | 63 | Should -Invoke -CommandName Write-Message -ParameterFilter { 64 | $Level -eq 'Error' -and $Message -like "*Failed to retrieve*" 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricWorkspaceUsageMetricsData.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricWorkspaceUsageMetricsData' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricWorkspaceUsageMetricsData 14 | } 15 | 16 | Describe "Get-FabricWorkspaceUsageMetricsData" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'workspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | @{ ExpectedParameterName = 'username'; ExpectedParameterType = 'string'; Mandatory = 'False' } 22 | ) { 23 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 24 | } 25 | } 26 | 27 | Context "Successful workspace usage metrics data retrieval" { 28 | BeforeAll { 29 | Mock -CommandName New-FabricWorkspaceUsageMetricsReport -MockWith { 30 | return [guid]::NewGuid() 31 | } 32 | Mock -CommandName Get-FabricUsageMetricsQuery -MockWith { 33 | return [pscustomobject]@{ 34 | results = @() 35 | } 36 | } 37 | } 38 | 39 | It 'Should get workspace usage metrics data with valid parameters' { 40 | $result = Get-FabricWorkspaceUsageMetricsData -workspaceId (New-Guid) 41 | 42 | $result | Should -Not -BeNullOrEmpty 43 | Should -Invoke -CommandName New-FabricWorkspaceUsageMetricsReport -Times 1 -Exactly 44 | Should -Invoke -CommandName Get-FabricUsageMetricsQuery -Times 7 -Exactly 45 | } 46 | } 47 | 48 | Context "Error handling" { 49 | BeforeAll { 50 | Mock -CommandName New-FabricWorkspaceUsageMetricsReport -MockWith { 51 | throw "API Error" 52 | } 53 | } 54 | 55 | It 'Should throw an error when API call fails' { 56 | { 57 | Get-FabricWorkspaceUsageMetricsData -workspaceId (New-Guid) 58 | } | Should -Throw 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /source/Public/Warehouse/Remove-FabricWarehouse.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricWarehouse 2 | { 3 | <# 4 | .SYNOPSIS 5 | Removes a warehouse from a specified Microsoft Fabric workspace. 6 | 7 | .DESCRIPTION 8 | This function sends a DELETE request to the Microsoft Fabric API to remove a warehouse 9 | from the specified workspace using the provided WorkspaceId and WarehouseId. 10 | 11 | .PARAMETER WorkspaceId 12 | The unique identifier of the workspace from which the warehouse will be removed. 13 | 14 | .PARAMETER WarehouseId 15 | The unique identifier of the warehouse to be removed. 16 | 17 | .EXAMPLE 18 | This example removes the warehouse with ID "warehouse-67890" from the workspace with ID "workspace-12345". 19 | 20 | ```powershell 21 | Remove-FabricWarehouse -WorkspaceId "workspace-12345" -WarehouseId "warehouse-67890" 22 | ``` 23 | .NOTES 24 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 25 | 26 | Author: Tiago Balabuch 27 | #> 28 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 29 | param ( 30 | [Parameter(Mandatory = $true)] 31 | [ValidateNotNullOrEmpty()] 32 | [guid]$WorkspaceId, 33 | 34 | [Parameter(Mandatory = $true)] 35 | [ValidateNotNullOrEmpty()] 36 | [guid]$WarehouseId 37 | ) 38 | try 39 | { 40 | # Step 1: Ensure token validity 41 | Confirm-TokenState 42 | 43 | # Step 2: Construct the API URL 44 | $apiEndpointURI = "workspaces/{0}/warehouses/{1}" -f $WorkspaceId, $WarehouseId 45 | 46 | if ($PSCmdlet.ShouldProcess($apiEndpointURI, "Delete Warehouse")) 47 | { 48 | # Step 3: Make the API request and Validate the response 49 | $apiParameters = @{ 50 | Uri = $apiEndpointURI 51 | Method = 'DELETE' 52 | HandleResponse = $true 53 | TypeName = "Warehouse" 54 | ObjectIdOrName = $WarehouseId 55 | } 56 | $response = Invoke-FabricRestMethod @apiParameters 57 | } 58 | 59 | # Step 4: Handle results 60 | $response 61 | 62 | } 63 | catch 64 | { 65 | # Step 5: Log and handle errors 66 | $errorDetails = $_.Exception.Message 67 | Write-Message -Message "Failed to delete Warehouse '$WarehouseId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /source/Public/Capacity/Suspend-FabricCapacity.ps1: -------------------------------------------------------------------------------- 1 | function Suspend-FabricCapacity { 2 | <# 3 | .SYNOPSIS 4 | Suspends a capacity. 5 | 6 | .DESCRIPTION 7 | The Suspend-FabricCapacity function suspends a capacity. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER SubscriptionID 10 | The ID of the subscription. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 11 | 12 | .PARAMETER ResourceGroup 13 | The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 14 | 15 | .PARAMETER Capacity 16 | The the capacity. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 17 | 18 | .EXAMPLE 19 | This example suspends a capacity given the subscription ID, resource group, and capacity. 20 | 21 | ```powershell 22 | Suspend-FabricCapacity -SubscriptionID "your-subscription-id" -ResourceGroup "your-resource-group" -Capacity "your-capacity" 23 | ``` 24 | 25 | .NOTES 26 | The function defines parameters for the subscription ID, resource group, and capacity. If the 'azToken' environment variable is null, it connects to the Azure account and sets the 'azToken' environment variable. It then defines the headers for the request, defines the URI for the request, and makes a GET request to the URI. 27 | 28 | Author: Ioana Bouariu 29 | 30 | #> 31 | # Define aliases for the function for flexibility. 32 | [Alias("Suspend-PowerBICapacity", "Suspend-FabCapacity")] 33 | [CmdletBinding(SupportsShouldProcess)] 34 | 35 | # Define parameters for the subscription ID, resource group, and capacity. 36 | Param ( 37 | [Parameter(Mandatory = $true)] 38 | [guid]$SubscriptionID, 39 | [Parameter(Mandatory = $true)] 40 | [string]$ResourceGroup, 41 | [Parameter(Mandatory = $true)] 42 | [string]$Capacity 43 | ) 44 | 45 | Confirm-TokenState 46 | 47 | $AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl' 48 | $headers = Get-PSFConfigValue 'FabricTools.AzureSession.Headers' 49 | 50 | # Define the URI for the request. 51 | $suspendCapacity = "$AzureBaseApiUrl/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Fabric/capacities/$Capacity/suspend?api-version=2023-11-01" 52 | 53 | # Make a GET request to the URI and return the response. 54 | if ($PSCmdlet.ShouldProcess("Suspend capacity $capacity")) { 55 | return Invoke-RestMethod -Method POST -Uri $suspendCapacity -Headers $headers -ErrorAction Stop 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /source/Public/Utils/Convert-ToBase64.ps1: -------------------------------------------------------------------------------- 1 | function Convert-ToBase64 { 2 | <# 3 | .SYNOPSIS 4 | Encodes the content of a file into a Base64-encoded string. 5 | 6 | .DESCRIPTION 7 | The Convert-ToBase64 function takes a file path as input, reads the file's content as a byte array, 8 | and converts it into a Base64-encoded string. This is useful for embedding binary data (e.g., images, 9 | documents) in text-based formats such as JSON or XML. 10 | 11 | .PARAMETER filePath 12 | The full path to the file whose contents you want to encode into Base64. 13 | 14 | .EXAMPLE 15 | Output: VGhpcyBpcyBhbiBlbmNvZGVkIGZpbGUu 16 | 17 | ```powershell 18 | Convert-ToBase64 -filePath "C:\Path\To\File.txt" 19 | ``` 20 | 21 | .EXAMPLE 22 | This saves the Base64-encoded content of the image to a text file. 23 | 24 | ```powershell 25 | $encodedContent = Convert-ToBase64 -filePath "C:\Path\To\Image.jpg 26 | 27 | $encodedContent | Set-Content -Path "C:\Path\To\EncodedImage.txt" This saves the Base64-encoded content of the image to a text file. 28 | ``` 29 | 30 | .NOTES 31 | - Ensure the file exists at the specified path before running this function. 32 | - Large files may cause memory constraints due to full loading into memory. 33 | 34 | Author: Tiago Balabuch 35 | 36 | #> 37 | 38 | [CmdletBinding()] 39 | [OutputType([System.String])] 40 | param ( 41 | [Parameter(Mandatory = $true)] 42 | [ValidateNotNullOrEmpty()] 43 | [string]$filePath 44 | ) 45 | try { 46 | 47 | # Step 1: Reading all the bytes from the file 48 | #$bytes = [System.Text.Encoding]::UTF8.GetBytes($InputString) 49 | Write-Message -Message "Reading all the bytes from the file specified: $filePath" -Level Debug 50 | $fileBytes = [System.IO.File]::ReadAllBytes($filePath) 51 | 52 | # Step 2: Convert the byte array to Base64 string 53 | Write-Message -Message "Convert the byte array to Base64 string" -Level Debug 54 | $base64String = [Convert]::ToBase64String($fileBytes) 55 | 56 | # Step 3: Return the encoded string 57 | Write-Message -Message "Return the encoded string for the file: $filePath" -Level Debug 58 | return $base64String 59 | } catch { 60 | # Step 4: Handle and log errors 61 | $errorDetails = $_.Exception.Message 62 | Write-Message -Message "An error occurred while encoding to Base64: $errorDetails" -Level Error 63 | throw "An error occurred while encoding to Base64: $_" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /source/Public/Capacity/Resume-FabricCapacity.ps1: -------------------------------------------------------------------------------- 1 | function Resume-FabricCapacity { 2 | <# 3 | .SYNOPSIS 4 | Resumes a capacity. 5 | 6 | .DESCRIPTION 7 | The Resume-FabricCapacity function resumes a capacity. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER SubscriptionID 10 | The the ID of the subscription. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 11 | 12 | .PARAMETER ResourceGroup 13 | The resource group. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 14 | 15 | .PARAMETER Capacity 16 | The capacity. This is a mandatory parameter. This is a parameter found in Azure, not Fabric. 17 | 18 | .EXAMPLE 19 | This example resumes a capacity given the subscription ID, resource group, and capacity. 20 | 21 | ```powershell 22 | Resume-FabricCapacity -SubscriptionID "your-subscription-id" -ResourceGroup "your-resource-group" -Capacity "your-capacity" 23 | ``` 24 | 25 | .NOTES 26 | The function defines parameters for the subscription ID, resource group, and capacity. If the 'azToken' environment variable is null, it connects to the Azure account and sets the 'azToken' environment variable. It then defines the headers for the request, defines the URI for the request, and makes a GET request to the URI. 27 | 28 | Author: Ioana Bouariu 29 | #> 30 | # Define aliases for the function for flexibility. 31 | [Alias("Resume-FabCapacity")] 32 | [CmdletBinding(SupportsShouldProcess)] 33 | 34 | # Define parameters for the subscription ID, resource group, and capacity. 35 | Param ( 36 | [Parameter(Mandatory = $true)] 37 | [guid]$SubscriptionID, 38 | [Parameter(Mandatory = $true)] 39 | [string]$ResourceGroup, 40 | [Parameter(Mandatory = $true)] 41 | [string]$Capacity 42 | ) 43 | 44 | Confirm-TokenState 45 | 46 | $AzureBaseApiUrl = Get-PSFConfigValue 'FabricTools.AzureApi.BaseUrl' 47 | $headers = Get-PSFConfigValue 'FabricTools.AzureSession.Headers' 48 | 49 | # Define the URI for the request. 50 | $resumeCapacity = "$AzureBaseApiUrl/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroup/providers/Microsoft.Fabric/capacities/$Capacity/resume?api-version=2022-07-01-preview" 51 | 52 | # Make a GET request to the URI and return the response. 53 | if ($PSCmdlet.ShouldProcess("Resume capacity $Capacity")) { 54 | return Invoke-RestMethod -Method POST -Uri $resumeCapacity -Headers $headers -ErrorAction Stop 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /source/Public/Domain/Get-FabricDomainWorkspace.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDomainWorkspace { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the workspaces associated with a specific domain in Microsoft Fabric. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricDomainWorkspace` function fetches the workspaces for the given domain ID. 8 | 9 | .PARAMETER DomainId 10 | The ID of the domain for which to retrieve workspaces. 11 | 12 | .EXAMPLE 13 | Fetches workspaces for the domain with ID "12345". 14 | 15 | ```powershell 16 | Get-FabricDomainWorkspace -DomainId "12345" 17 | ``` 18 | 19 | .NOTES 20 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 21 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 22 | 23 | Author: Tiago Balabuch 24 | 25 | #> 26 | [CmdletBinding()] 27 | param ( 28 | [Parameter(Mandatory = $true)] 29 | [ValidateNotNullOrEmpty()] 30 | [guid]$DomainId 31 | ) 32 | 33 | try { 34 | # Step 1: Ensure token validity 35 | Confirm-TokenState 36 | 37 | # Step 2: Construct the API URL 38 | $apiEndpointUrl = "{0}/admin/domains/{1}/workspaces" -f $FabricConfig.BaseUrl, $DomainId 39 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 40 | 41 | # Step 3: Make the API request 42 | $response = Invoke-FabricRestMethod ` 43 | -Uri $apiEndpointUrl ` 44 | -Method Get 45 | 46 | # Step 4: Validate the response code 47 | if ($statusCode -ne 200) { 48 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 49 | Write-Message -Message "Error: $($response.message)" -Level Error 50 | Write-Message "Error Code: $($response.errorCode)" -Level Error 51 | return $null 52 | } 53 | 54 | # Step 5: Handle empty response 55 | if (-not $response) { 56 | Write-Message -Message "No data returned from the API." -Level Warning 57 | return $null 58 | } 59 | # Step 6: Handle results 60 | if ($response) { 61 | return $response.value 62 | } else { 63 | Write-Message -Message "No workspace found for the '$DomainId'." -Level Warning 64 | return $null 65 | } 66 | 67 | } catch { 68 | # Step 7: Capture and log error details 69 | $errorDetails = $_.Exception.Message 70 | Write-Message -Message "Failed to retrieve domain workspaces. Error: $errorDetails" -Level Error 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineOperation.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDeploymentPipelineOperation { 2 | <# 3 | .SYNOPSIS 4 | Retrieves details of a specific deployment pipeline operation. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricDeploymentPipelineOperation` function fetches detailed information about a specific deployment operation 8 | performed on a deployment pipeline, including the deployment execution plan, status, and timing information. 9 | 10 | .PARAMETER DeploymentPipelineId 11 | Required. The ID of the deployment pipeline. 12 | 13 | .PARAMETER OperationId 14 | Required. The ID of the operation to retrieve. 15 | 16 | .EXAMPLE 17 | Retrieves details of a specific deployment operation, including its execution plan and status. 18 | 19 | ```powershell 20 | Get-FabricDeploymentPipelineOperation -DeploymentPipelineId "GUID-GUID-GUID-GUID" -OperationId "GUID-GUID-GUID-GUID" 21 | ``` 22 | 23 | .NOTES 24 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 25 | - Returns detailed operation information including: 26 | - Operation status and type 27 | - Execution timing 28 | - Source and target stage information 29 | - Deployment execution plan with steps 30 | - Pre-deployment diff information 31 | - Performed by information 32 | - Requires Pipeline.Read.All or Pipeline.ReadWrite.All delegated scopes. 33 | 34 | Author: Kamil Nowinski 35 | #> 36 | [CmdletBinding()] 37 | param( 38 | [Parameter(Mandatory = $true)] 39 | [ValidateNotNullOrEmpty()] 40 | [Guid]$DeploymentPipelineId, 41 | 42 | [Parameter(Mandatory = $true)] 43 | [ValidateNotNullOrEmpty()] 44 | [Guid]$OperationId 45 | ) 46 | 47 | try { 48 | # Step 1: Ensure token validity 49 | Confirm-TokenState 50 | 51 | # Step 2: Construct the API URL 52 | $apiEndpointUrl = "deploymentPipelines/$DeploymentPipelineId/operations/$OperationId" 53 | 54 | # Step 3: Make the API request 55 | $apiParameters = @{ 56 | Uri = $apiEndpointUrl 57 | Method = 'GET' 58 | HandleResponse = $true 59 | TypeName = "deployment pipeline operation" 60 | ObjectIdOrName = $DeploymentPipelineId 61 | } 62 | $response = Invoke-FabricRestMethod @apiParameters 63 | 64 | $response 65 | 66 | } catch { 67 | # Step 6: Error handling 68 | $errorDetails = $_.Exception.Message 69 | Write-Error -Message "Failed to retrieve deployment pipeline operation. Error: $errorDetails" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricDashboard.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricDashboard' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricDashboard 14 | } 15 | 16 | Describe "Get-FabricDashboard" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'WorkspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful dashboard retrieval" { 27 | BeforeAll { 28 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 29 | InModuleScope -ModuleName 'FabricTools' { 30 | $script:statusCode = 200 31 | } 32 | return [pscustomobject]@{ 33 | value = @( 34 | [pscustomobject]@{ id = 'dashboard-guid'; displayName = 'TestDashboard' } 35 | ) 36 | } 37 | } 38 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 39 | } 40 | 41 | It 'Should return dashboards when WorkspaceId is provided' { 42 | $result = Get-FabricDashboard -WorkspaceId (New-Guid) 43 | 44 | $result | Should -Not -BeNullOrEmpty 45 | 46 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 47 | } 48 | } 49 | 50 | Context "Error handling" { 51 | BeforeAll { 52 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 53 | throw "API Error" 54 | } 55 | Mock -CommandName Confirm-TokenState -MockWith { } 56 | Mock -CommandName Write-Message -MockWith { } 57 | } 58 | 59 | It 'Should handle errors gracefully and call Write-Message with Error level' { 60 | Get-FabricDashboard -WorkspaceId (New-Guid) 61 | Should -Invoke -CommandName Write-Message -ParameterFilter { 62 | $Level -eq 'Error' 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/Unit/Invoke-FabricDatasetRefresh.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Invoke-FabricDatasetRefresh' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Invoke-FabricDatasetRefresh 14 | } 15 | 16 | Describe "Invoke-FabricDatasetRefresh" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'DatasetID'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful dataset refresh invocation" -Skip { 27 | # Skipped: Function calls Get-FabricDataset which does not exist in the module 28 | BeforeAll { 29 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 30 | return $null 31 | } 32 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 33 | Mock -CommandName Get-FabricDataset -MockWith { 34 | return @{ isrefreshable = $true } 35 | } 36 | } 37 | 38 | It 'Should invoke dataset refresh with valid parameters' { 39 | { Invoke-FabricDatasetRefresh -DatasetID ([guid]::NewGuid()) } | Should -Not -Throw 40 | 41 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 42 | } 43 | } 44 | 45 | Context "Error handling" -Skip { 46 | # Skipped: Function calls Get-FabricDataset which does not exist in the module 47 | BeforeAll { 48 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 49 | throw "API Error" 50 | } 51 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 52 | Mock -CommandName Get-FabricDataset -MockWith { 53 | return @{ isrefreshable = $true } 54 | } 55 | } 56 | 57 | It 'Should throw an error when API call fails' { 58 | { 59 | Invoke-FabricDatasetRefresh -DatasetID ([guid]::NewGuid()) 60 | } | Should -Throw 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /source/Public/Workspace/Remove-FabricWorkspace.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricWorkspace { 2 | <# 3 | .SYNOPSIS 4 | Deletes an existing Fabric workspace by its workspace ID. 5 | 6 | .DESCRIPTION 7 | The `Remove-FabricWorkspace` function deletes a workspace in the Fabric platform by sending a DELETE request to the API. It validates the workspace ID and handles both success and error responses. 8 | 9 | .PARAMETER WorkspaceId 10 | The unique identifier of the workspace to be deleted. 11 | 12 | .EXAMPLE 13 | Deletes the workspace with the ID "workspace123". 14 | 15 | ```powershell 16 | Remove-FabricWorkspace -WorkspaceId "workspace123" 17 | ``` 18 | 19 | .NOTES 20 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 21 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 22 | 23 | Author: Tiago Balabuch 24 | #> 25 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 26 | param ( 27 | [Parameter(Mandatory = $true)] 28 | [ValidateNotNullOrEmpty()] 29 | [guid]$WorkspaceId 30 | ) 31 | 32 | try 33 | { 34 | # Step 1: Ensure token validity 35 | Confirm-TokenState 36 | 37 | # Step 2: Construct the API URL 38 | $apiEndpointUrl = "{0}/workspaces/{1}" -f $FabricConfig.BaseUrl, $WorkspaceId 39 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 40 | 41 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Delete Workspace")) 42 | { 43 | # Step 3: Make the API request 44 | $response = Invoke-FabricRestMethod ` 45 | -Uri $apiEndpointUrl ` 46 | -Method Delete 47 | } 48 | 49 | # Step 4: Validate the response code 50 | if ($statusCode -ne 200) 51 | { 52 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 53 | Write-Message -Message "Error: $($response.message)" -Level Error 54 | Write-Message "Error Code: $($response.errorCode)" -Level Error 55 | return $null 56 | } 57 | 58 | Write-Message -Message "Workspace '$WorkspaceId' deleted successfully!" -Level Info 59 | return $null 60 | 61 | } 62 | catch 63 | { 64 | # Step 5: Capture and log error details 65 | $errorDetails = $_.Exception.Message 66 | Write-Message -Message "Failed to retrieve capacity. Error: $errorDetails" -Level Error 67 | return $null 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/Unit/Update-FabricCopyJobDefinition.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Update-FabricCopyJobDefinition' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Update-FabricCopyJobDefinition 14 | } 15 | 16 | Describe "Update-FabricCopyJobDefinition" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'WorkspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | @{ ExpectedParameterName = 'CopyJobId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 22 | @{ ExpectedParameterName = 'CopyJobPathDefinition'; ExpectedParameterType = 'string'; Mandatory = 'True' } 23 | @{ ExpectedParameterName = 'CopyJobPathPlatformDefinition'; ExpectedParameterType = 'string'; Mandatory = 'False' } 24 | ) { 25 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 26 | } 27 | 28 | It 'Should support ShouldProcess' { 29 | $Command.Parameters.ContainsKey('WhatIf') | Should -BeTrue 30 | $Command.Parameters.ContainsKey('Confirm') | Should -BeTrue 31 | } 32 | } 33 | 34 | Context "Error handling" { 35 | BeforeAll { 36 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 37 | InModuleScope -ModuleName 'FabricTools' { 38 | $script:statusCode = 400 39 | } 40 | throw "API Error" 41 | } 42 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 43 | Mock -CommandName Write-Message -MockWith { } 44 | Mock -CommandName Convert-ToBase64 -ModuleName FabricTools -MockWith { return 'base64encodedcontent' } 45 | } 46 | 47 | It 'Should handle errors gracefully and write error message' { 48 | { Update-FabricCopyJobDefinition -WorkspaceId (New-Guid) -CopyJobId (New-Guid) -CopyJobPathDefinition 'TestPath' -Confirm:$false } | Should -Not -Throw 49 | 50 | Should -Invoke -CommandName Write-Message -ParameterFilter { 51 | $Level -eq 'Error' 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricWorkspaceDatasetRefreshes.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricWorkspaceDatasetRefreshes' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricWorkspaceDatasetRefreshes 14 | } 15 | 16 | Describe "Get-FabricWorkspaceDatasetRefreshes" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'WorkspaceID'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful workspace dataset refreshes retrieval" -Skip { 27 | # Skipped: Function calls Get-FabricDataset which does not exist in the module 28 | BeforeAll { 29 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 30 | Mock -CommandName Get-FabricWorkspace -MockWith { 31 | return [pscustomobject]@{ Id = [guid]::NewGuid(); displayName = 'TestWorkspace' } 32 | } 33 | Mock -CommandName Get-FabricDatasetRefreshes -MockWith { 34 | return @( 35 | [pscustomobject]@{ id = 'refresh-1'; status = 'Completed' } 36 | ) 37 | } 38 | } 39 | 40 | It 'Should get workspace dataset refreshes with valid parameters' { 41 | $result = Get-FabricWorkspaceDatasetRefreshes -WorkspaceID (New-Guid) 42 | 43 | Should -Invoke -CommandName Get-FabricWorkspace -Times 1 -Exactly 44 | Should -Invoke -CommandName Get-FabricDatasetRefreshes -Times 1 -Exactly 45 | } 46 | } 47 | 48 | Context "Error handling" { 49 | BeforeAll { 50 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 51 | Mock -CommandName Get-FabricWorkspace -MockWith { 52 | throw "API Error" 53 | } 54 | } 55 | 56 | It 'Should throw an error when API call fails' { 57 | { 58 | Get-FabricWorkspaceDatasetRefreshes -WorkspaceID (New-Guid) 59 | } | Should -Throw 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricSparkSettings.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricSparkSettings' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricSparkSettings 14 | } 15 | 16 | Describe "Get-FabricSparkSettings" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'WorkspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful Spark settings retrieval" { 27 | BeforeAll { 28 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 29 | InModuleScope -ModuleName 'FabricTools' { 30 | $script:statusCode = 200 31 | } 32 | return [pscustomobject]@{ 33 | automaticLog = [pscustomobject]@{ enabled = $true } 34 | highConcurrency = [pscustomobject]@{ notebookInteractiveRunEnabled = $true } 35 | } 36 | } 37 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 38 | } 39 | 40 | It 'Should return Spark settings when WorkspaceId is provided' { 41 | $result = Get-FabricSparkSettings -WorkspaceId (New-Guid) 42 | 43 | $result | Should -Not -BeNullOrEmpty 44 | 45 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 46 | } 47 | } 48 | 49 | Context "Error handling" { 50 | BeforeAll { 51 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 52 | throw "API Error" 53 | } 54 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 55 | Mock -CommandName Write-Message -MockWith { } 56 | } 57 | 58 | It 'Should handle errors gracefully' { 59 | { 60 | Get-FabricSparkSettings -WorkspaceId (New-Guid) 61 | } | Should -Not -Throw 62 | 63 | Should -Invoke -CommandName Write-Message -ParameterFilter { 64 | $Level -eq 'Error' 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /source/Public/External Data Share/Revoke-FabricExternalDataShares.ps1: -------------------------------------------------------------------------------- 1 | function Revoke-FabricExternalDataShares { 2 | 3 | <# 4 | .SYNOPSIS 5 | Retrieves External Data Shares details from a specified Microsoft Fabric. 6 | 7 | .DESCRIPTION 8 | This function retrieves External Data Shares details. 9 | It handles token validation, constructs the API URL, makes the API request, and processes the response. 10 | 11 | .PARAMETER WorkspaceId 12 | The unique identifier of the workspace where the External Data Shares resides. 13 | 14 | .PARAMETER ItemId 15 | The unique identifier of the item associated with the External Data Shares. 16 | 17 | .PARAMETER ExternalDataShareId 18 | The unique identifier of the External Data Share to be retrieved. 19 | 20 | .EXAMPLE 21 | This example retrieves the External Data Shares details 22 | 23 | ```powershell 24 | Get-FabricExternalDataShares 25 | ``` 26 | 27 | .NOTES 28 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 29 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 30 | 31 | Author: Tiago Balabuch 32 | #> 33 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 34 | param ( 35 | [Parameter(Mandatory = $true)] 36 | [ValidateNotNullOrEmpty()] 37 | [guid]$WorkspaceId, 38 | 39 | [Parameter(Mandatory = $true)] 40 | [ValidateNotNullOrEmpty()] 41 | [guid]$ItemId, 42 | 43 | [Parameter(Mandatory = $true)] 44 | [ValidateNotNullOrEmpty()] 45 | [guid]$ExternalDataShareId 46 | ) 47 | 48 | try { 49 | 50 | # Step 2: Ensure token validity 51 | Confirm-TokenState 52 | 53 | # Step 4: Loop to retrieve all capacities with continuation token 54 | Write-Message -Message "Constructing API endpoint URI..." -Level Debug 55 | $apiEndpointURI = "admin/workspaces/{0}/items/{1}/externalDataShares/{2}/revoke" -f $WorkspaceId, $ItemId, $ExternalDataShareId 56 | 57 | if ($PSCmdlet.ShouldProcess("$ExternalDataShareId", "revoke")) { 58 | 59 | $externalDataShares = Invoke-FabricRestMethod ` 60 | -Uri $apiEndpointURI ` 61 | -Method Post 62 | } 63 | 64 | # Step 4: Return retrieved data 65 | Write-Message -Message "Successfully revoked external data shares." -Level Info 66 | return $externalDataShares 67 | } catch { 68 | # Step 10: Capture and log error details 69 | $errorDetails = $_.Exception.Message 70 | Write-Message -Message "Failed to retrieve External Data Shares. Error: $errorDetails" -Level Error 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /source/Public/Deployment Pipeline/Get-FabricDeploymentPipelineStageItem.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricDeploymentPipelineStageItem { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the supported items from the workspace assigned to a specific stage of a deployment pipeline. 5 | 6 | .DESCRIPTION 7 | The `Get-FabricDeploymentPipelineStageItem` function returns a list of supported items from the workspace 8 | assigned to the specified stage of a deployment pipeline. The function automatically handles pagination 9 | and returns all available items. 10 | 11 | .PARAMETER DeploymentPipelineId 12 | Required. The ID of the deployment pipeline. 13 | 14 | .PARAMETER StageId 15 | Required. The ID of the stage to retrieve items from. 16 | 17 | .EXAMPLE 18 | Retrieves all items from the specified stage of the deployment pipeline. 19 | 20 | ```powershell 21 | Get-FabricDeploymentPipelineStageItem -DeploymentPipelineId "GUID-GUID-GUID-GUID" -StageId "GUID-GUID-GUID-GUID" 22 | ``` 23 | 24 | .NOTES 25 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 26 | - Requires Pipeline.Read.All or Pipeline.ReadWrite.All delegated scope. 27 | - Requires admin deployment pipelines role. 28 | - The user must be at least a workspace contributor assigned to the specified stage. 29 | - Returns items with their metadata including: 30 | - Item ID and display name 31 | - Item type (Report, Dashboard, SemanticModel, etc.) 32 | - Source and target item IDs (if applicable) 33 | - Last deployment time (if applicable) 34 | 35 | Author: Kamil Nowinski 36 | #> 37 | [CmdletBinding()] 38 | param( 39 | [Parameter(Mandatory = $true)] 40 | [ValidateNotNullOrEmpty()] 41 | [Guid]$DeploymentPipelineId, 42 | 43 | [Parameter(Mandatory = $true)] 44 | [ValidateNotNullOrEmpty()] 45 | [Guid]$StageId 46 | ) 47 | 48 | try { 49 | # Step 1: Ensure token validity 50 | Confirm-TokenState 51 | 52 | # Step 3: Construct the API URL 53 | $apiEndpointUrl = "deploymentPipelines/$DeploymentPipelineId/stages/$StageId/items" 54 | 55 | # Step 4: Make the API request 56 | $apiParameters = @{ 57 | Uri = $apiEndpointUrl 58 | Method = 'GET' 59 | HandleResponse = $true 60 | TypeName = "deployment pipeline stage items" 61 | ObjectIdOrName = $StageId 62 | } 63 | $response = Invoke-FabricRestMethod @apiParameters 64 | 65 | $response 66 | 67 | } catch { 68 | # Step 8: Error handling 69 | $errorDetails = $_.Exception.Message 70 | Write-Error -Message "Failed to retrieve deployment pipeline stage items. Error: $errorDetails" 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /source/Public/Notebook/Remove-FabricNotebook.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricNotebook 2 | { 3 | <# 4 | .SYNOPSIS 5 | Deletes an Notebook from a specified workspace in Microsoft Fabric. 6 | 7 | .DESCRIPTION 8 | The `Remove-FabricNotebook` function sends a DELETE request to the Fabric API to remove a specified Notebook from a given workspace. 9 | 10 | .PARAMETER WorkspaceId 11 | (Mandatory) The ID of the workspace containing the Notebook to delete. 12 | 13 | .PARAMETER NotebookId 14 | (Mandatory) The ID of the Notebook to be deleted. 15 | 16 | .EXAMPLE 17 | Deletes the Notebook with ID "67890" from workspace "12345". 18 | 19 | ```powershell 20 | Remove-FabricNotebook -WorkspaceId "12345" -NotebookId "67890" 21 | ``` 22 | 23 | .NOTES 24 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 25 | - Validates token expiration before making the API request. 26 | 27 | Author: Tiago Balabuch 28 | 29 | #> 30 | [CmdletBinding(SupportsShouldProcess)] 31 | param ( 32 | [Parameter(Mandatory = $true)] 33 | [ValidateNotNullOrEmpty()] 34 | [guid]$WorkspaceId, 35 | 36 | [Parameter(Mandatory = $true)] 37 | [ValidateNotNullOrEmpty()] 38 | [guid]$NotebookId 39 | ) 40 | 41 | try 42 | { 43 | # Step 1: Ensure token validity 44 | Confirm-TokenState 45 | 46 | # Step 2: Construct the API URL 47 | $apiEndpointUrl = "{0}/workspaces/{1}/notebooks/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $NotebookId 48 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 49 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Notebook")) 50 | { 51 | # Step 3: Make the API request 52 | $response = Invoke-FabricRestMethod ` 53 | -Uri $apiEndpointUrl ` 54 | -Method Delete 55 | } 56 | 57 | # Step 4: Validate the response code 58 | if ($statusCode -ne 200) 59 | { 60 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 61 | Write-Message -Message "Error: $($response.message)" -Level Error 62 | Write-Message "Error Code: $($response.errorCode)" -Level Error 63 | return $null 64 | } 65 | Write-Message -Message "Notebook '$NotebookId' deleted successfully from workspace '$WorkspaceId'." -Level Info 66 | 67 | } 68 | catch 69 | { 70 | # Step 5: Log and handle errors 71 | $errorDetails = $_.Exception.Message 72 | Write-Message -Message "Failed to delete notebook '$NotebookId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /source/Public/Workspace/Remove-FabricWorkspaceCapacityAssignment.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricWorkspaceCapacityAssignment 2 | { 3 | <# 4 | .SYNOPSIS 5 | Unassigns a Fabric workspace from its capacity. 6 | 7 | .DESCRIPTION 8 | The `Remove-FabricWorkspaceCapacityAssignment` function sends a POST request to unassign a workspace from its assigned capacity. 9 | 10 | .PARAMETER WorkspaceId 11 | The unique identifier of the workspace to be unassigned from its capacity. 12 | 13 | .EXAMPLE 14 | Unassign the workspace with ID "workspace123" from its capacity. 15 | 16 | ```powershell 17 | Remove-FabricWorkspaceCapacityAssignment -WorkspaceId "workspace123" 18 | ``` 19 | 20 | .NOTES 21 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 22 | - Calls `Confirm-TokenState` to ensure token validity before making the API request. 23 | 24 | Author: Tiago Balabuch 25 | #> 26 | [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] 27 | [Alias("Unassign-FabricWorkspaceCapacity")] 28 | param ( 29 | [Parameter(Mandatory = $true)] 30 | [ValidateNotNullOrEmpty()] 31 | [guid]$WorkspaceId 32 | ) 33 | try 34 | { 35 | # Step 1: Ensure token validity 36 | Confirm-TokenState 37 | 38 | # Step 2: Construct the API URL 39 | $apiEndpointUrl = "{0}/workspaces/{1}/unassignFromCapacity" -f $FabricConfig.BaseUrl, $WorkspaceId 40 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Message 41 | 42 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Unassign Workspace from Capacity")) 43 | { 44 | # Step 3: Make the API request 45 | $response = Invoke-FabricRestMethod ` 46 | -Uri $apiEndpointUrl ` 47 | -Method Post 48 | } 49 | # Step 4: Validate the response code 50 | if ($statusCode -ne 202) 51 | { 52 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 53 | Write-Message -Message "Error: $($response.message)" -Level Error 54 | Write-Message "Error Code: $($response.errorCode)" -Level Error 55 | return $null 56 | } 57 | 58 | Write-Message -Message "Workspace capacity has been successfully unassigned from workspace '$WorkspaceId'." -Level Info 59 | } 60 | catch 61 | { 62 | # Step 5: Capture and log error details 63 | $errorDetails = $_.Exception.Message 64 | Write-Message -Message "Failed to unassign workspace from capacity. Error: $errorDetails" -Level Error 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricLongRunningOperationResult.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricLongRunningOperationResult' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricLongRunningOperationResult 14 | } 15 | 16 | Describe "Get-FabricLongRunningOperationResult" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'operationId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | ) { 22 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 23 | } 24 | } 25 | 26 | Context "Successful operation result retrieval" { 27 | BeforeAll { 28 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 29 | InModuleScope -ModuleName 'FabricTools' { 30 | $script:statusCode = 200 31 | } 32 | return [pscustomobject]@{ 33 | definition = [pscustomobject]@{ 34 | parts = @( 35 | [pscustomobject]@{ path = 'item.json'; payload = 'encodedPayload' } 36 | ) 37 | } 38 | } 39 | } 40 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 41 | } 42 | 43 | It 'Should return operation result when operationId is provided' { 44 | $result = Get-FabricLongRunningOperationResult -operationId ([guid]::NewGuid()) 45 | 46 | $result | Should -Not -BeNullOrEmpty 47 | 48 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 49 | } 50 | } 51 | 52 | Context "Error handling" { 53 | BeforeAll { 54 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 55 | throw "API Error" 56 | } 57 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 58 | Mock -CommandName Write-Message -MockWith { } 59 | } 60 | 61 | It 'Should throw an error when API call fails' { 62 | { 63 | Get-FabricLongRunningOperationResult -operationId ([guid]::NewGuid()) 64 | } | Should -Throw 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /source/Public/Lakehouse/Remove-FabricLakehouse.ps1: -------------------------------------------------------------------------------- 1 | function Remove-FabricLakehouse 2 | { 3 | <# 4 | .SYNOPSIS 5 | Deletes an Lakehouse from a specified workspace in Microsoft Fabric. 6 | 7 | .DESCRIPTION 8 | The `Remove-FabricLakehouse` function sends a DELETE request to the Fabric API to remove a specified Lakehouse from a given workspace. 9 | 10 | .PARAMETER WorkspaceId 11 | (Mandatory) The ID of the workspace containing the Lakehouse to delete. 12 | 13 | .PARAMETER LakehouseId 14 | (Mandatory) The ID of the Lakehouse to be deleted. 15 | 16 | .EXAMPLE 17 | Deletes the Lakehouse with ID "67890" from workspace "12345". 18 | 19 | ```powershell 20 | Remove-FabricLakehouse -WorkspaceId "12345" -LakehouseId "67890" 21 | ``` 22 | 23 | .NOTES 24 | - Requires `$FabricConfig` global configuration, including `BaseUrl` and `FabricHeaders`. 25 | - Validates token expiration before making the API request. 26 | 27 | Author: Tiago Balabuch 28 | 29 | #> 30 | [CmdletBinding(SupportsShouldProcess)] 31 | param ( 32 | [Parameter(Mandatory = $true)] 33 | [ValidateNotNullOrEmpty()] 34 | [guid]$WorkspaceId, 35 | 36 | [Parameter(Mandatory = $true)] 37 | [ValidateNotNullOrEmpty()] 38 | [guid]$LakehouseId 39 | ) 40 | 41 | try 42 | { 43 | # Step 1: Ensure token validity 44 | Confirm-TokenState 45 | 46 | # Step 2: Construct the API URL 47 | $apiEndpointUrl = "{0}/workspaces/{1}/lakehouses/{2}" -f $FabricConfig.BaseUrl, $WorkspaceId, $LakehouseId 48 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 49 | if ($PSCmdlet.ShouldProcess($apiEndpointUrl, "Remove Lakehouse")) 50 | { 51 | # Step 3: Make the API request 52 | $response = Invoke-FabricRestMethod ` 53 | -Uri $apiEndpointUrl ` 54 | -Method Delete 55 | } 56 | 57 | # Step 4: Validate the response code 58 | if ($statusCode -ne 200) 59 | { 60 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 61 | Write-Message -Message "Error: $($response.message)" -Level Error 62 | Write-Message "Error Code: $($response.errorCode)" -Level Error 63 | return $null 64 | } 65 | Write-Message -Message "Lakehouse '$LakehouseId' deleted successfully from workspace '$WorkspaceId'." -Level Info 66 | 67 | } 68 | catch 69 | { 70 | # Step 5: Log and handle errors 71 | $errorDetails = $_.Exception.Message 72 | Write-Message -Message "Failed to delete Lakehouse '$LakehouseId' from workspace '$WorkspaceId'. Error: $errorDetails" -Level Error 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /source/Public/Workspace/Get-FabricWorkspaceUsageMetricsData.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricWorkspaceUsageMetricsData { 2 | <# 3 | .SYNOPSIS 4 | Retrieves workspace usage metrics data. 5 | 6 | .DESCRIPTION 7 | The Get-FabricWorkspaceUsageMetricsData function retrieves workspace usage metrics. It supports multiple aliases for flexibility. 8 | 9 | .PARAMETER workspaceId 10 | The ID of the workspace. This is a mandatory parameter. 11 | 12 | .PARAMETER username 13 | The username. This is a mandatory parameter. 14 | 15 | .EXAMPLE 16 | This example retrieves the workspace usage metrics for a specific workspace given the workspace ID and username. 17 | 18 | ```powershell 19 | Get-FabricWorkspaceUsageMetricsData -workspaceId "your-workspace-id" -username "your-username" 20 | ``` 21 | 22 | .NOTES 23 | The function retrieves the PowerBI access token and creates a new usage metrics report. It then defines the names of the reports to retrieve, initializes an empty hashtable to store the reports, and for each report name, retrieves the report and adds it to the hashtable. It then returns the hashtable of reports. 24 | 25 | Author: Ioana Bouariu 26 | 27 | #> 28 | 29 | # Define aliases for the function for flexibility. 30 | [Alias("Get-FabWorkspaceUsageMetricsData")] 31 | 32 | # Define parameters for the workspace ID and username. 33 | param( 34 | [Parameter(Mandatory = $true)] 35 | [guid]$WorkspaceId, 36 | [Parameter(Mandatory = $false)] 37 | [string]$username = "" 38 | ) 39 | 40 | # Create a new workspace usage metrics dataset. 41 | $datasetId = New-FabricWorkspaceUsageMetricsReport -workspaceId $workspaceId 42 | 43 | # Define the names of the reports to retrieve. 44 | $reportnames = @("'Workspace views'", "'Report pages'", "Users", "Reports", "'Report views'", "'Report page views'", "'Report load times'") 45 | 46 | # Initialize an empty hashtable to store the reports. 47 | $reports = @{ } 48 | 49 | # For each report name, retrieve the report and add it to the hashtable. 50 | if ($username -eq "") { 51 | foreach ($reportname in $reportnames) { 52 | $report = Get-FabricUsageMetricsQuery -DatasetID $datasetId -groupId $workspaceId -reportname $reportname 53 | $reports += @{ $reportname.replace("'", "") = $report } 54 | } 55 | } else { 56 | foreach ($reportname in $reportnames) { 57 | $report = Get-FabricUsageMetricsQuery -DatasetID $datasetId -groupId $workspaceId -reportname $reportname -ImpersonatedUser $username 58 | $reports += @{ $reportname.replace("'", "") = $report } 59 | } 60 | } 61 | # Return the hashtable of reports. 62 | return $reports 63 | } 64 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Pull Request 2 | 3 | 18 | 19 | ## Pull Request (PR) description 20 | 21 | 44 | 45 | ## Task list 46 | 47 | 55 | 56 | - [ ] The PR represents a single logical change. i.e. Cosmetic updates should go in different PRs. 57 | - [ ] Added an entry under the Unreleased section of in the CHANGELOG.md as per [format](https://keepachangelog.com/en/1.0.0/). 58 | - [ ] Local clean build passes without issue or fail tests (`build.ps1 -ResolveDependency -Tasks build, test`). 59 | - [ ] Comment-based help added/updated. 60 | - [ ] Examples appropriately added/updated. 61 | - [ ] Unit tests added/updated.. 62 | - [ ] Integration tests added/updated (where possible). 63 | - [ ] Documentation added/updated (where applicable). 64 | - [ ] Code follows the [contribution guidelines](https://github.com/dataplat/FabricTools/blob/develop/CONTRIBUTING.md). 65 | -------------------------------------------------------------------------------- /source/Public/Environment/Get-FabricEnvironmentLibrary.ps1: -------------------------------------------------------------------------------- 1 | function Get-FabricEnvironmentLibrary { 2 | <# 3 | .SYNOPSIS 4 | Retrieves the list of libraries associated with a specific environment in a Microsoft Fabric workspace. 5 | 6 | .DESCRIPTION 7 | The Get-FabricEnvironmentLibrary function fetches library information for a given workspace and environment 8 | using the Microsoft Fabric API. It ensures the authentication token is valid and validates the response 9 | to handle errors gracefully. 10 | 11 | .PARAMETER WorkspaceId 12 | (Mandatory) The unique identifier of the workspace where the environment is located. 13 | 14 | .PARAMETER EnvironmentId 15 | The unique identifier of the environment whose libraries are being queried. 16 | 17 | .EXAMPLE 18 | Retrieves the libraries associated with the specified environment in the given workspace. 19 | 20 | ```powershell 21 | Get-FabricEnvironmentLibrary -WorkspaceId "workspace-12345" -EnvironmentId "environment-67890" 22 | ``` 23 | 24 | .NOTES 25 | - Requires the `$FabricConfig` global object, including `BaseUrl` and `FabricHeaders`. 26 | - Uses `Confirm-TokenState` to validate the token before making API calls. 27 | 28 | Author: Tiago Balabuch 29 | #> 30 | [CmdletBinding()] 31 | param ( 32 | [Parameter(Mandatory = $true)] 33 | [ValidateNotNullOrEmpty()] 34 | [guid]$WorkspaceId, 35 | 36 | [Parameter(Mandatory = $true)] 37 | [ValidateNotNullOrEmpty()] 38 | [guid]$EnvironmentId 39 | ) 40 | 41 | try { 42 | # Step 1: Ensure token validity 43 | Confirm-TokenState 44 | 45 | # Step 2: Construct the API URL 46 | $apiEndpointUrl = "{0}/workspaces/{1}/environments/{2}/libraries" -f $FabricConfig.BaseUrl, $WorkspaceId, $EnvironmentId 47 | Write-Message -Message "API Endpoint: $apiEndpointUrl" -Level Debug 48 | 49 | # Step 3: Make the API request 50 | $response = Invoke-FabricRestMethod ` 51 | -Uri $apiEndpointUrl ` 52 | -Method Get 53 | 54 | # Step 4: Validate the response code 55 | if ($statusCode -ne 200) { 56 | Write-Message -Message "Unexpected response code: $statusCode from the API." -Level Error 57 | Write-Message -Message "Error: $($response.message)" -Level Error 58 | Write-Message "Error Code: $($response.errorCode)" -Level Error 59 | return $null 60 | } 61 | 62 | # Step 5: Handle results 63 | return $response 64 | } catch { 65 | # Step 6: Capture and log error details 66 | $errorDetails = $_.Exception.Message 67 | Write-Message -Message "Failed to retrieve environment libraries. Error: $errorDetails" -Level Error 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /tests/Unit/Get-FabricUserListAccessEntities.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Get-FabricUserListAccessEntities' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Get-FabricUserListAccessEntities 14 | } 15 | 16 | Describe "Get-FabricUserListAccessEntities" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'UserId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | @{ ExpectedParameterName = 'Type'; ExpectedParameterType = 'string'; Mandatory = 'False' } 22 | ) { 23 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 24 | } 25 | } 26 | 27 | Context "Successful user access entities retrieval" { 28 | BeforeAll { 29 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 30 | InModuleScope -ModuleName 'FabricTools' { 31 | $script:statusCode = 200 32 | } 33 | return [pscustomobject]@{ 34 | accessEntities = @( 35 | [pscustomobject]@{ id = 'entity-1'; type = 'Workspace' } 36 | ) 37 | } 38 | } 39 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 40 | } 41 | 42 | It 'Should get user access entities with valid parameters' { 43 | $result = Get-FabricUserListAccessEntities -UserId (New-Guid) 44 | 45 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 46 | } 47 | } 48 | 49 | Context "Error handling" { 50 | BeforeAll { 51 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 52 | throw "API Error" 53 | } 54 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 55 | Mock -CommandName Write-Message -MockWith { } 56 | } 57 | 58 | It 'Should handle errors gracefully' { 59 | { 60 | Get-FabricUserListAccessEntities -UserId (New-Guid) 61 | } | Should -Not -Throw 62 | 63 | Should -Invoke -CommandName Write-Message -ParameterFilter { 64 | $Level -eq 'Error' 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/Unit/Import-FabricEnvironmentStagingLibrary.Tests.ps1: -------------------------------------------------------------------------------- 1 | #Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} 2 | 3 | BeforeDiscovery { 4 | $CommandName = 'Import-FabricEnvironmentStagingLibrary' 5 | } 6 | 7 | BeforeAll { 8 | $ModuleName = 'FabricTools' 9 | $PSDefaultParameterValues['Mock:ModuleName'] = $ModuleName 10 | $PSDefaultParameterValues['InModuleScope:ModuleName'] = $ModuleName 11 | $PSDefaultParameterValues['Should:ModuleName'] = $ModuleName 12 | 13 | $Command = Get-Command -Name Import-FabricEnvironmentStagingLibrary 14 | } 15 | 16 | Describe "Import-FabricEnvironmentStagingLibrary" -Tag "UnitTests" { 17 | 18 | Context "Command definition" { 19 | It 'Should have parameter' -ForEach @( 20 | @{ ExpectedParameterName = 'WorkspaceId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 21 | @{ ExpectedParameterName = 'EnvironmentId'; ExpectedParameterType = 'guid'; Mandatory = 'True' } 22 | ) { 23 | $Command | Should -HaveParameter -ParameterName $ExpectedParameterName -Type $ExpectedParameterType -Mandatory:([bool]::Parse($Mandatory)) 24 | } 25 | } 26 | 27 | Context "Successful environment staging library import" { 28 | BeforeAll { 29 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 30 | InModuleScope -ModuleName 'FabricTools' { 31 | $script:statusCode = 200 32 | } 33 | return [pscustomobject]@{ 34 | libraries = @() 35 | } 36 | } 37 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 38 | } 39 | 40 | It 'Should import environment staging library with valid parameters' { 41 | $result = Import-FabricEnvironmentStagingLibrary -WorkspaceId (New-Guid) -EnvironmentId (New-Guid) 42 | 43 | Should -Invoke -CommandName Invoke-FabricRestMethod -Times 1 -Exactly 44 | } 45 | } 46 | 47 | Context "Error handling" { 48 | BeforeAll { 49 | Mock -CommandName Invoke-FabricRestMethod -MockWith { 50 | throw "API Error" 51 | } 52 | Mock -CommandName Confirm-TokenState -MockWith { return $true } 53 | Mock -CommandName Write-Message -MockWith { } 54 | } 55 | 56 | It 'Should handle errors gracefully' { 57 | { 58 | Import-FabricEnvironmentStagingLibrary -WorkspaceId (New-Guid) -EnvironmentId (New-Guid) 59 | } | Should -Not -Throw 60 | 61 | Should -Invoke -CommandName Write-Message -ParameterFilter { 62 | $Level -eq 'Error' 63 | } 64 | } 65 | } 66 | } 67 | --------------------------------------------------------------------------------