Skip to content

Adding scripts for self-serve item deletion - #629

Merged
Mark Pryce-Maher (MarkPryceMaherMSFT) merged 6 commits into
microsoft:mainfrom
avermams:tenant-remap-automated-deletion
Aug 21, 2026
Merged

Adding scripts for self-serve item deletion#629
Mark Pryce-Maher (MarkPryceMaherMSFT) merged 6 commits into
microsoft:mainfrom
avermams:tenant-remap-automated-deletion

Conversation

@avermams

@avermams Avi Verma (avermams) commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Pull Request

Pull Request (PR) description

Task list

  • The PR represents a single logical change. i.e. Cosmetic updates should go in different PRs.
  • Added an entry under the Unreleased section of in the CHANGELOG.md as per format.
  • Local clean build passes without issue or fail tests (build.ps1 -ResolveDependency -Tasks build, test).
  • Comment-based help added/updated.
  • Examples appropriately added/updated.
  • Unit tests added/updated..
  • Integration tests added/updated (where possible).
  • Documentation added/updated (where applicable).
  • Code follows the contribution guidelines.

Copilot AI lite review requested due to automatic review settings August 10, 2026 02:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread scripts/tenant-remap-automated-deletion/Step0.ps1
Comment thread scripts/tenant-remap-automated-deletion/Step1.ps1
Comment thread scripts/tenant-remap-automated-deletion/Step2.ps1
Comment on lines +32 to +34
$adminOid = (Get-AzADUser -UserPrincipalName $AdminUpn).Id
$adminEmailAddress = (Get-AzADUser -UserPrincipalName $AdminUpn).mail

Comment thread scripts/tenant-remap-automated-deletion/Step4.ps1
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 thread scripts/tenant-remap-automated-deletion/Step5.ps1
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

Comment thread scripts/tenant-remap-automated-deletion/Step6.ps1
@MarkPryceMaherMSFT
Mark Pryce-Maher (MarkPryceMaherMSFT) merged commit 050ceef into microsoft:main Aug 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants