更改cosmosDB吞吐量的Powershell脚本给出401错误

时间:2019-01-30 04:25:43

标签: azure powershell azure-cosmosdb azure-cli

我正在尝试使用Powershell更改cosmosDB吞吐量

当我运行以下脚本时,它给了我这个错误,但此后仍然可以正常工作

  

“获取令牌”请求返回的HTTP错误:401和服务器响应:   {“错误”:“ invalid_client”,“错误描述”:“ AADSTS50012:无效   提供了客户机密。\ r \ n跟踪ID:GUID \ r \ n相关ID:   GUID \ r \ n时间戳:2019年1月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

如果我不将密码转换为安全字符串,则可以正常工作。我该如何解决上述脚本,使其不会出现401错误?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以添加以下代码的第二行,这样对我有用。

$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 >'

请参阅此document

输出:

enter image description here