-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Workspace-SearchAndDelete.ps1
49 lines (33 loc) · 1.28 KB
/
Workspace-SearchAndDelete.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Requires -Modules @{ ModuleName="MicrosoftPowerBIMgmt"; ModuleVersion="1.2.1026" }
# This script requires you to authenticate with a Power BI Admin account
param(
$searchPattern = @("*PBIDevOps*", "Test*")
)
$ErrorActionPreference = "Stop"
$VerbosePreference = "SilentlyContinue"
Connect-PowerBIServiceAccount
$workspaces = Get-PowerBIWorkspace -Scope Organization -All -Filter "tolower(state) eq 'active'"
$filteredWorkspaces = @(
$workspaces |? {
$workspaceName = $_.Name
$searchPattern |? { $workspaceName -like $_}
}
)
if ($filteredWorkspaces.Count -eq 0)
{
Write-Host "No active workspaces found where Workspace Name like $([string]::join(",", $searchPattern))"
}
else
{
# TODO - Its not possible to delete workspace as admin, but its possible to add yourself as admin and delete afterq
Write-Host "Found '$($filteredWorkspaces.Count)' workspaces"
$filteredWorkspaces | Format-Table
$confirmation = Read-Host "Are you Sure You Want To Proceed (y)"
if ($confirmation -ieq 'y') {
foreach($workspace in $filteredWorkspaces)
{
Write-Host "Deleting Workspace: $($workspace.Name)"
Invoke-PowerBIRestMethod -Method Delete -Url "groups/$($workspace.id)"
}
}
}