Describe the bug
When entering the following azure cli command from a Powershell window:
az ad sp create-for-rbac -n "Demo" --role contributor --scopes /subscriptions/{SubscriptionId}
I get the following errormessage:
az ad sp create-for-rbac: 'utputformat' is not a valid value for '--output'. See 'az ad sp create-for-rbac --help'.
To Reproduce Enter the cli command Expected behavior Environment summary acr 2.2.2 Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Python (Windows) 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 02:47:15) [MSC v.1900 32 bit (Intel)] Legal docs and information: aka.ms/AzureCliLegal Your CLI is up-to-date. C:> $PSVersionTable Name Value C:> [System.Environment]::OSVersion.Version Major Minor Build Revision 10 0 17134 0
Open an Powershell windows with admin rights
az login
az ad sp create-for-rbac -n "Demo" --role contributor --scopes /subscriptions/{SubscriptionId}
A service principal is created in AAD.
I should see the service principal credentials in json as output.
C:> az --version
azure-cli 2.0.60
acs 2.3.19
advisor 2.0.0
ams 0.4.2
appservice 0.2.15
backup 1.2.1
batch 4.0.0
batchai 0.4.7
billing 0.2.0
botservice 0.1.8
cdn 0.2.0
cloud 2.1.0
cognitiveservices 0.2.4
command-modules-nspkg 2.0.2
configure 2.0.20
consumption 0.4.2
container 0.3.15
core 2.0.60
cosmosdb 0.2.8
dla 0.2.4
dls 0.1.8
dms 0.1.2
eventgrid 0.2.1
eventhubs 0.3.4
extension 0.2.3
feedback 2.1.4
find 0.3.0
hdinsight 0.3.2
interactive 0.4.1
iot 0.3.6
iotcentral 0.1.6
keyvault 2.2.12
kusto 0.2.0
lab 0.1.5
maps 0.3.3
monitor 0.2.10
network 2.3.4
nspkg 3.0.3
policyinsights 0.1.1
profile 2.1.3
rdbms 0.3.8
redis 0.4.1
relay 0.1.3
reservations 0.4.1
resource 2.1.11
role 2.4.2
search 0.1.1
security 0.1.0
servicebus 0.3.3
servicefabric 0.1.14
signalr 1.0.0
sql 2.1.9
sqlvm 0.1.0
storage 2.3.1
telemetry 1.0.1
vm 2.2.16
Extensions directory 'C:\Users\Albert.azure\cliextensions'
---- -----
PSVersion 5.1.17134.590
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.590
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Could you try the same command with --debug and show me the first couple lines?
C:\WINDOWS\system32> az ad sp create-for-rbac -n "Demo" --role contributor --scopes /subscriptions/{removed subscriptionid} --debug
File logging enabled - writing logs to 'C:\Users\Albert.azure\logs'.
Command arguments: ['ad', 'sp', 'create-for-rbac', '-n', 'Demo', '--role', 'contributor', '--scopes', '/subscriptions/', '-encodedCommand', 'ZAA2ADUAMgA1ADIAYwAxAC0AMQA3AGIAZgAtADQAZQA0AGMALQA4ADEAMwAwAC0AOQBiADAAYgAxADYANwBjADEAZQA5ADAA', '--debug', '-inputFormat', 'xml', '-outputFormat', 'text']
Event: Cli.PreExecute []
Event: CommandParser.OnGlobalArgumentsCreate [
Event: CommandInvoker.OnPreCommandTableCreate []
Installed command modules ['acr', 'acs', 'advisor', 'ams', 'appservice', 'backup', 'batch', 'batchai', 'billing', 'botservice', 'cdn', 'cloud', 'cognitiveservices', 'configure', 'consumption', 'container', 'cosmosdb', 'dla', 'dls', 'dms', 'eventgrid', 'eventhubs', 'extension', 'feedback', 'find', 'hdinsight', 'interactive', 'iot', 'iotcentral', 'keyvault', 'kusto', 'lab', 'maps', 'monitor', 'network', 'policyinsights', 'profile', 'rdbms', 'redis', 'relay', 'reservations', 'resource', 'role', 'search', 'security', 'servicebus', 'servicefabric', 'signalr', 'sql', 'sqlvm', 'storage', 'vm']
Loaded module 'acr' in 0.014 seconds.
...
-encodedCommand, -inputFormat, -outputFormat are not valid anything in the CLI. Did you add these? Looks like it may be some Powershell feature you need to turn off.
No, I did not add these. I updated the CLI to the latest version. I do not know how to add parameters... :-)
But I figured it out what the problem is. I used {} around the subcriptionid, like this:
az ad sp create-for-rbac -n "Demo" --role contributor --scopes /subscriptions/{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
Then I get the error. When I removed the {}, everything works fine:
az ad sp create-for-rbac -n "Demo" --role contributor --scopes /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Changing "Demo" to a valid URI of "http://Demo", which is the required format used for service principal names
Retrying role assignment creation: 1/36
{
"appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"displayName": "Demo",
"name": "http://Demo",
"password": "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb",
"tenant": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy"
}
I used the example in the packer documentation (https://www.packer.io/docs/builders/azure-setup.html) to create the service principal. Here it is defined as follows:
az ad sp create-for-rbac -n "Packer" --role contributor \
--scopes /subscriptions/{SubID}
Ah, okay. Thanks for the update @kjoebie! Yes, in any examples the curly-braces are used to denote placeholders. I'm not sure what Powershell features interprets them and puts those parameters on the cmd line, but this is very good to know if we encounter this again!