【问题标题】:Set-AzureSubscription : Cannot bind parameter 'Certificate'Set-AzureSubscription:无法绑定参数“证书”
【发布时间】:2014-12-02 23:28:54
【问题描述】:

使用 PowerShell 在 azure 帐户中更改 CurrentStorageAccountName 时出现以下错误:

Set-AzureSubscription : Cannot bind parameter 'Certificate'. Cannot convert value
"0EA9BE03CD1C2E5B93DB176F89C2CC2EF147B96C" to type "System.Security.Cryptography.X509Certificates.X509Certificate2".
Error: "The system cannot find the file specified.

代码是:

Set-AzureSubscription -SubscriptionName Enterprise -Certificate 0EA9BE03CD1C2E5B93DB176F89C2CC2EF147B96C -CurrentStorageAccountName btestps -SubscriptionId XXXXXXXXXXXXXXXXXXXXXXXXXXX

【问题讨论】:

  • get-help set-azuresubscription -full
  • 帮助包含几个使用证书指纹的示例以及如何将其应用于-Certificate

标签: powershell azure-storage


【解决方案1】:

我最近需要这样做,您需要实际获取或构建一个 X509Certificate2 对象,然后将其传递给 -certificate 参数。

要通过指纹使用本地用户证书存储中的证书设置证书,您可以:

# open the local user certificate store as read-only 
$store = new-object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser)
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
# get all the certificates in the store
$certs = $store.Certificates;
# restrict the selection to only currently valid certificates
$currentcerts = $certs.Find([System.Security.Cryptography.X509Certificates.X509FindType]::FindByTimeValid, [System.DateTime]::Now, 0)
# get the first certificate by thumbprint, you could also find by distinguished name, subject name, etc 
$signingCert = $currentcerts.Find([System.Security.Cryptography.X509Certificates.X509FindType]::FindByThumbprint,"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",0)[0]
# set the certificate
set-azuresubscription -certificate $signingCert
# open the local user certificate store as read-only 
$store = new-object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser)

【讨论】:

    【解决方案2】:

    一个更简单的解决方案是使用这个:

    $Certificate = Get-Item cert:\\LocalMachine\My\$CertificateThumbprint
    Set-AzureSubscription -SubscriptionName Enterprise -Certificate $Certificate
    

    假设证书在 LocalMachine\My 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多