首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >连接-AzAccount:无法绑定参数‘凭据’。无法转换"System.Management.Automation.PSCredential“

连接-AzAccount:无法绑定参数‘凭据’。无法转换"System.Management.Automation.PSCredential“
EN

Stack Overflow用户
提问于 2022-02-08 14:22:56
回答 1查看 510关注 0票数 0

据我所知,类似的问题以前也曾在堆栈过流本身中被问过和回答过。但我的要求略有不同。我的要求是使用服务主体登录到Azure,我也使用下面的PowerShell脚本,

代码语言:javascript
复制
$azureAppId = "#######"
$azureAppIdPassword = "######"
$userPassword = ConvertTo-SecureString -String $azureAppIdPassword -AsPlainText -Force
$azureAppCred = (New-Object System.Management.Automation.PSCredential ($azureAppId, $userPassword))
 
$subscriptionId = '######'
$tenantId = '######'
Connect-AzAccount -ServicePrincipal -SubscriptionId $subscriptionId -TenantId $tenantId -Credential $azureAppCred
$containerId = Invoke-Expression -Command "docker run -d  -it  mcr.microsoft.com/azure-powershell"
docker exec $containerId pwsh -c  Connect-AzAccount -ServicePrincipal -SubscriptionId $subscriptionId -TenantId $tenantId -Credential $azureAppCred

上面的脚本与错误Connect-AzAccount: Cannot bind parameter 'Credential'. Cannot convert the "System.Security.SecureString" value of type "System.String" to type "System.Management.Automation.PSCredential".一起失败,如果我在没有停靠器的情况下执行上面的脚本,它就会运行得很好。

我尝试使用命令$azureAppCred打印docker exec $containerId pwsh -c Write-Host $azureAppCred类型,它按预期打印System.Management.Automation.PSCredential,但是登录命令仍然失败。

有人能告诉我这里可能出了什么问题吗?

谢谢你,廷图

EN

回答 1

Stack Overflow用户

发布于 2022-02-09 07:41:57

如本 中所述,azure登录与docker登录不同。当您使用服务主体连接azure并运行docker命令时,您可以使用如下所示的内容:

代码语言:javascript
复制
$azureAppId = "#######"
$azureAppIdPassword = "######"
$tenantId = '######'
docker login azure --client-id $azureAppId --client-secret $azureAppIdPassword --tenant-id $tenantId
docker run -d  -it  mcr.microsoft.com/azure-powershell
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71035505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档