Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
LucyRose
Regular 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 a list of reports the user has access to using:

 

Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/users/$userId/artifactAccess" -Method Get

 

 

The plan was to amend the JSON & Post this back but I am getting an error message.

"WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod)"


I have hundreds of users so manually doing this in the service is not an option.

Any insight would be greatly appreciated, I am happy to change the method to anything that works.

 

 

# Convert JSON string to PowerShell object
$artifactAccess = ConvertFrom-Json $artifactAccessJsonGet

# Iterate through each artifact and update accessRight to 'None'
foreach ($artifact in $artifactAccess.ArtifactAccessEntities) {
$artifact.accessRight = 'None'
}
# Convert the updated object back to JSON
$body = $artifactAccess | ConvertTo-Json

Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/users/$userId/artifactAccess" -Method Post -Body $body -ContentType "application/json"

 


Many thanks

2 REPLIES 2
Anonymous
Not 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

So the verbose error I am receiving is  MethodNotAllowed (405). 
It may be what I am including in my JSON. I am unsure whether to PUT, PATCH or POST & can not find any API specific documentation from Microsoft. Still, I find it hard to believe that we cannot administer access changes to reports at the report level. This is an example result of the earlier GET.  

 
{
"@odata.context":"https:/xxxxxxeContracts.Api.Access.ArtifactAccessResponse",
"ArtifactAccessEntities":[
    {
"artifactId":"1xxxxxxx","displayName":"Report1","artifactType":"Report","accessRight":"ReadReshare"
    },{
      "artifactId":"2xxxxx","displayName":"Report2","artifactType":"Report","accessRight":"ReadCopy"
}
  ],"continuationUri":"https:/xxxxxxxx/artifactAccess?continuationToken='Lrrrrrrr'","continuationToken":"Lrrrrr"
} 

I have tried to invoke using just the ArtifactAccessEntities, & the whole thing including odata.context etc. 
Same result.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.