0
votes

I am trying to change cosmosDB throughput using powershell

When I run the following script, I it gives me this error but it work fine after that

Get Token request returned http error: 401 and server response: {"error":"invalid_client","error_description":"AADSTS50012: Invalid client secret is provided.\r\nTrace ID: GUID\r\nCorrelation ID: GUID\r\nTimestamp: 2019-01-30 03:59:07Z","error_codes":[50012],"timestamp":"2019-01-30 03:59:07Z","trace_id":"GUID","correlation_id":"GUID"}

$SecurePw = ConvertTo-SecureString $DeploymentServicePrincipalPassword -AsPlainText -Force
az login --service-principal -u $DeploymentServicePrincipalId -p $SecurePw --tenant $TenantId
az account set --subscription $SubscriptionId
az cosmosdb collection update --collection-name $CollectionName --name $AccountName --db-name $DBName --resource-group $ResourceGroupName --throughput $Throughput

If I don't convert the password to secure string, then it just works fine. How can I fix above script so that it does not give me the 401 error?

Thanks

1
Hi,does my answer helps you?If so,you could mark it to end this case, thank you very much,.Jay Gong

1 Answers

1
votes

You could add the second line of following code and it works me.

$SecurePw = ConvertTo-SecureString '<your secret>' -AsPlainText -Force
$AzPass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePw));
az login --service-principal -u '<your client id>' -p $AzPass --tenant '<your tenant id >'

Please refer to this document.

Output:

enter image description here