<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Use PowerBIRestMethod to remove user from all PowerBI artifacts in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4053638#M54271</link>
    <description>&lt;P&gt;So the verbose error I am receiving is&amp;nbsp; MethodNotAllowed (405).&amp;nbsp;&lt;BR /&gt;It may be what I am including in my JSON. I am unsure whether to PUT, PATCH or POST &amp;amp; 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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;{
"@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"
} &lt;/LI-CODE&gt;&lt;P&gt;I have tried to invoke using just the&amp;nbsp;&lt;SPAN&gt;ArtifactAccessEntities, &amp;amp; the whole thing including odata.context etc.&amp;nbsp;&lt;BR /&gt;Same result.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jul 2024 09:38:02 GMT</pubDate>
    <dc:creator>LucyRose</dc:creator>
    <dc:date>2024-07-22T09:38:02Z</dc:date>
    <item>
      <title>Use PowerBIRestMethod to remove user from all PowerBI artifacts</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4041981#M54179</link>
      <description>&lt;P&gt;Context:&amp;nbsp;&lt;BR /&gt;I have users not deleted from AD&amp;nbsp;(entra) by design. However, I want to remove them from PowerBI reports/BI-App/etc.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I am BI-admin&lt;/LI&gt;&lt;LI&gt;I have already removed users from Workspaces&lt;/LI&gt;&lt;LI&gt;I can get a list of reports the user has access to using:&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Invoke-PowerBIRestMethod -Url "https://api.powerbi.com/v1.0/myorg/admin/users/$userId/artifactAccess" -Method Get&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The plan was to&amp;nbsp;amend the JSON &amp;amp; Post this back but I am getting an error message.&lt;/P&gt;&lt;P&gt;&lt;FONT size="2" color="#FF0000"&gt;"WriteError: (Microsoft.Power...werBIRestMethod:InvokePowerBIRestMethod)"&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have hundreds of users so manually doing this in the service is not an option.&lt;/P&gt;&lt;P&gt;Any insight would be greatly appreciated, I am happy to change the method to anything that works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Many thanks&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 07:58:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4041981#M54179</guid>
      <dc:creator>LucyRose</dc:creator>
      <dc:date>2024-07-15T07:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use PowerBIRestMethod to remove user from all PowerBI artifacts</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4043238#M54189</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/168702"&gt;@LucyRose&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Base on your description, it works to&amp;nbsp;get the list of artifacts and modify the access rights&lt;/SPAN&gt;&lt;SPAN&gt;. However,&amp;nbsp;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:&lt;/SPAN&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;# 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: $_"
}&lt;/LI-CODE&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 01:49:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4043238#M54189</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-16T01:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Use PowerBIRestMethod to remove user from all PowerBI artifacts</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4053638#M54271</link>
      <description>&lt;P&gt;So the verbose error I am receiving is&amp;nbsp; MethodNotAllowed (405).&amp;nbsp;&lt;BR /&gt;It may be what I am including in my JSON. I am unsure whether to PUT, PATCH or POST &amp;amp; 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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;LI-CODE lang="python"&gt;{
"@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"
} &lt;/LI-CODE&gt;&lt;P&gt;I have tried to invoke using just the&amp;nbsp;&lt;SPAN&gt;ArtifactAccessEntities, &amp;amp; the whole thing including odata.context etc.&amp;nbsp;&lt;BR /&gt;Same result.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jul 2024 09:38:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Use-PowerBIRestMethod-to-remove-user-from-all-PowerBI-artifacts/m-p/4053638#M54271</guid>
      <dc:creator>LucyRose</dc:creator>
      <dc:date>2024-07-22T09:38:02Z</dc:date>
    </item>
  </channel>
</rss>

