Forum Discussion
LucyRose
2 years agoRegular Visitor
Use PowerBIRestMethod to remove user from all PowerBI artifacts
Context: I have users not deleted from AD (entra) by design. However, I want to remove them from PowerBI reports/BI-App/etc. I am BI-admin I have already removed users from Workspaces I can get...
Anonymous
2 years agoNot applicable
Hi LucyRose ,
Base on your description, it works to get the list of artifacts and modify the access rights. However, it seems like there is some issue with the permissions or the way the JSON is constructed. Please try to update the codes as below and check if it can get works:
# Ensure you're logged in as an admin
Connect-PowerBIServiceAccount
# Retrieve the artifact access data
try {
$artifactAccessJsonGet = Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/users/$userId/artifactAccess" -Method Get
} catch {
Write-Error "Failed to retrieve artifact access data: $_"
break
}
# Check if data retrieval was successful
if (!$artifactAccessJsonGet) {
Write-Error "No data retrieved."
break
}
# Convert JSON string to PowerShell object
try {
$artifactAccess = ConvertFrom-Json $artifactAccessJsonGet
} catch {
Write-Error "Failed to convert JSON to PowerShell object: $_"
break
}
# Iterate through each artifact and update accessRight to 'None'
foreach ($artifact in $artifactAccess.ArtifactAccessEntities) {
$artifact.accessRight = 'None'
}
# Convert the updated object back to JSON
try {
$body = $artifactAccess | ConvertTo-Json
} catch {
Write-Error "Failed to convert PowerShell object to JSON: $_"
break
}
# Post the updated JSON back to the API
try {
Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/users/$userId/artifactAccess" -Method Post -Body $body -ContentType "application/json" -Verbose
} catch {
Write-Error "Failed to update artifact access: $_"
}
Best Regards