Forum Discussion
Leafde
2 years agoNew Member
Add/Remove/Update Organization Wide Sharing Links
Hello, We are doing some clean up of sharing links in our environment and are investigating the possibility of seeing if we can programatically complete the process instead of doing it manually. ...
Leafde
2 years agoNew Member
_willie_ Anonymous Just posting an additional update here for you both, I could not find any workarounds to do this programatically so I just did it manually.
- _willie_2 years agoNew Member
Hi Leafde
Sorry to hear you had to delete each one manually.
In case this helps anyone we ended putting together a few commands and ran the following
# Check for Power BI Module and install if not found Write-Host "Checking for Power BI Module" try { Import-Module MicrosoftPowerBIMgmt.Profile } catch { Install-Module -Name MicrosoftPowerBIMgmt.Profile -Force -AllowClobber Import-Module MicrosoftPowerBIMgmt.Profile } if (!(Get-Module -ListAvailable -Name MicrosoftPowerBIMgmt.Profile)) { throw "Module MicrosoftPowerBIMgmt.Profile not found" } # Enter your Power BI Service URL # Can be found using F12 > Network > Headers > Request URL $pbiServiceURL = "https://wabi-us-east2-redirect.analysis.windows.net" # Connect to PowerBI Service Write-Host "Connecting to Power BI Service" $loginInfo = Connect-PowerBIServiceAccount Write-Host "Logged in as $($loginInfo.UserName)" # Set token for Power BI API $token = (Get-PowerBIAccessToken).Authorization # Get all workspaces Write-Host "Getting all workspaces" $aWorkspaces = @() $tResults = Invoke-PowerBIRestMethod -Url 'admin/groups?$top=5000&$skip=0' -Method GET $aWorkspaces = ($tResults | ConvertFrom-Json).value $tResults = $null # Traverse each workspace foreach ($workspace in $aWorkspaces) { # Grant Admin Access to Workspace Add-PowerBIWorkspaceUser -Id $workspace.Id -Scope Organization -UserPrincipalName $loginInfo.UserName -AccessRight Admin Write-Host "Sleeping for 10 seconds..." Start-Sleep -s 10 $workspaceName = $workspace.Name Write-Host "Currently on $($workspaceName)" # get list of workspaces $lWorkspaceURL = "$($pbiServiceURL)/powerbi/metadata/refreshusermetadata" $rWorkspace = Invoke-WebRequest -Uri $lWorkspaceURL -Method PUT -Headers @{ "Authorization" = "$token" } # get reports for the workspace # artfactId eq 2 is for reports $artifactIds = $null $artifactIds = (($rWorkspace.Content | ConvertFrom-Json).artifactOwnerInfo | Where-Object { $_.groupDisplayName -eq $workspaceName -and $_.artifactType -eq '2' }).artifactId # traverse each report foreach ($artifactId in $artifactIds) { # get report links $reportLinkURL = "$($pbiServiceURL)/metadata/links/report/$artifactId" $rLinks = Invoke-WebRequest -Uri $reportLinkURL -Method GET -Headers @{ "Authorization" = "$token" } -ErrorAction Stop # convert json to object $links = $null $links = $rLinks.Content | ConvertFrom-Json # traverse each link foreach ($link in $links) { # if link is for entire org if ($link.entireOrg -eq $true -and $link.artifactType -eq '2') { $linkId = $link.id $linkURL = "$($pbiServiceURL)/metadata/links/$linkId" $tResult = Invoke-WebRequest -Uri $linkURL -Method DELETE -Headers @{ "Authorization" = "$token" } Write-Host "`tRemoved Link for $($linkId) for $($workspaceName)" } } } # Remove Admin Access to Workspace Remove-PowerBIWorkspaceUser -Id $workspace.Id -Scope Organization -UserPrincipalName $loginInfo.UserName Write-Host "" }the script is AS IS and would suggest testing to ensure it works with the intended environment.