How do you run New-AzRoleAssignment in noninteractive mode?

Viewed 183

I'm running the following cmdlet:

New-AzRoleAssignment -Scope $workspaceid -RoleDefinitionId $roleId -ObjectId $objectid -verbose -debug

Error I'm getting is:

Powershell is in noninteractive mode.  Read and prompt functionality is unavailable.

Fair enough. So I try running it with the -Force switch, returns error:

A parameter cannot be found that matches the parameter name "Force".

Try with "-confirm:$false", get an error that says:

A parameter cannot be found that matches the parameter name "confirm".

If neither "confirm" nor "force" work, then why is it complaining about being in noninteractive mode?

2 Answers

It seems this Az module's cmdlet doesn't work while executing in the non-interactive mode (for example, by using a pipeline). I managed to overcome this by just toggling to Azure CLI.

Instead of this: New-AzRoleAssignment -ObjectId $objectid -RoleDefinitionId $roleId -Scope $workspaceid

use this: az role assignment create --assignee $objectID --role $roleId --scope $workspaceid

Note: if you need to assign a role to an application identity (for instance, Databrics), --assignee is the applicationId from the App registration, non objectID.

Please check if the below findings help to fix the issue:

  • Many workarounds suggesting the same parameters to pass for this kind of error in PowerShell like passing the parameters -Force and -Confirm:$false to the PowerShell Commands.

  • Try including this parameter also for that PowerShell command e.g., Enable-WindowsOptionalFeature

Related