Search code examples
azure-powershell

what is the equivalent "az ad sp create-for-rbac" in powershell az


What is the equivalent of az command in powershell

az ad sp create-for-rbac --query "{ client_id: appId, client_secret: password, tenant_id: tenant }"

What extra parameters should I add to New-AzADServicePrincipal

az ad sp create-for-rbac Create a service principal and configure its access to Azure resources.

I would like to do the same with powershell az command


Solution

  • If you want to create an Azure AD service principle by command : New-AzADServicePrincipal and get its client id, client secret and tenant id as cli command replies , try command below :

    $sp = New-AzADServicePrincipal 
    $clientsec = [System.Net.NetworkCredential]::new("", $sp.Secret).Password
    $tenantID = (get-aztenant).Id
    $jsonresp = 
    @{client_id=$sp.ApplicationId 
        client_secret=$clientsec
        tenant_id=$tenantID}
    $jsonresp | ConvertTo-Json
    

    Result :

    enter image description here