Adding scripts for self-serve item deletion - #629
Merged
Mark Pryce-Maher (MarkPryceMaherMSFT) merged 6 commits intoAug 21, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new, step-based PowerShell workflow under scripts/tenant-remap-automated-deletion/ to support self-serve cleanup/deletion operations across Microsoft Fabric/Power BI workspaces (collect workspace IDs, restore deleted workspaces, adjust capacity/admin access, and hard-delete items).
Changes:
- Adds Step0–Step6 PowerShell scripts to enumerate workspaces, restore deleted workspaces, and perform admin/access setup needed for cleanup.
- Adds scripts to hard-delete active artifacts and recoverable (soft-deleted) artifacts with basic throttling retry handling.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/tenant-remap-automated-deletion/Step0.ps1 | Enumerates tenant workspaces and writes shared/personal/all workspace ID lists to disk. |
| scripts/tenant-remap-automated-deletion/Step1.ps1 | Restores deleted workspaces via the admin restore API, assigning a new admin/name. |
| scripts/tenant-remap-automated-deletion/Step2.ps1 | Assigns workspaces to a specified capacity (if currently unassigned). |
| scripts/tenant-remap-automated-deletion/Step3.ps1 | Adds admin access to shared workspaces using the Power BI Admin API. |
| scripts/tenant-remap-automated-deletion/Step4.ps1 | Grants temporary admin access to personal workspaces with throttling handling. |
| scripts/tenant-remap-automated-deletion/Step5.ps1 | Hard-deletes all active workspace artifacts, with export and retry-on-429. |
| scripts/tenant-remap-automated-deletion/Step6.ps1 | Hard-deletes all soft-deleted (recoverable) artifacts, with export and retry-on-429. |
Suppressed comments (1)
scripts/tenant-remap-automated-deletion/Step3.ps1:39
- This script calls the Power BI Admin API (api.powerbi.com), but the access token is requested for https://api.fabric.microsoft.com and then treated as a SecureString. The repo’s Fabric tooling uses https://analysis.windows.net/powerbi/api as the token resource for Fabric/Power BI admin API calls (see tools/MicrosoftFabricMgmt/source/prefix.ps1 and Connect-FabricAccount.ps1). Request the token with -AsSecureString for the Power BI resource to avoid auth failures and runtime type errors.
$secureFabricToken = (Get-AzAccessToken -ResourceUrl 'https://api.fabric.microsoft.com').Token
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureFabricToken)
$plainTextFabricToken = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
$h = @{ Authorization = "Bearer $plainTextFabricToken"; 'Content-Type' = 'application/json' }
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+32
to
+34
| $adminOid = (Get-AzADUser -UserPrincipalName $AdminUpn).Id | ||
| $adminEmailAddress = (Get-AzADUser -UserPrincipalName $AdminUpn).mail | ||
|
|
Comment on lines
+58
to
+69
| } catch { | ||
| $error_returned = $_.Exception.Response.StatusCode | ||
|
|
||
| if ($error_returned -ne 429) { | ||
| Write-Warning "API grant failed for $wsId ($error_returned). This may happen if already Admin. Use UI link if NOT already Admin: https://app.powerbi.com/groups/$wsId" | ||
| break | ||
| } | ||
|
|
||
| # 429 error case | ||
| # docs: https://learn.microsoft.com/en-us/rest/api/fabric/articles/throttling | ||
| $retryAfter = $_.Exception.Response.Headers.RetryAfter | ||
|
|
Comment on lines
+81
to
+90
| catch { | ||
| $error_returned = $_.Exception.Response.StatusCode | ||
|
|
||
| if ($error_returned -ne 429) { | ||
| Write-Warning "Deletion API failed for $($artifact.id) ($error_returned)" | ||
| break | ||
| } | ||
|
|
||
| $retryAfter = $_.Exception.Response.Headers.RetryAfter | ||
|
|
Comment on lines
+80
to
+89
| catch { | ||
| $error_returned = $_.Exception.Response.StatusCode | ||
|
|
||
| if ($error_returned -ne 429) { | ||
| Write-Warning "Deletion API failed for $($artifact.id) ($error_returned)" | ||
| break | ||
| } | ||
|
|
||
| $retryAfter = $_.Exception.Response.Headers.RetryAfter | ||
|
|
…ring, and context
Mark Pryce-Maher (MarkPryceMaherMSFT)
approved these changes
Aug 21, 2026
Mark Pryce-Maher (MarkPryceMaherMSFT)
merged commit Aug 21, 2026
050ceef
into
microsoft:main
1 check passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Pull Request (PR) description
Task list
build.ps1 -ResolveDependency -Tasks build, test).