Programmatically configure PIM for Azure subscription role resource

MrFlinstone 656 Reputation points
2025-04-11T12:23:55.4133333+00:00

According to the documentation here it is possible to call Azure API's to configure PIM for Azure resources, I am trying to set this up at the subscription level, i.e contributor for a subscription.

I have the script as follows.

Connect-AzAccount

# Variables

I get the error.

Invoke-RestMethod : {"error":{"code":"SubjectNotFound","message":"The subject is not found."}}
At line:1 char:13
+ $response = Invoke-RestMethod -Method Put -Uri $url -Headers $headers ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,914 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.