2014-10-08 54 views
0

而在蔚藍的帳戶改變CurrentStorageAccountName使用PowerShell的我收到以下錯誤:設置-AzureSubscription:無法綁定參數「證書」

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 
+1

'get-help set-azuresubscription -full' – arco444 2014-10-08 11:31:48

+0

該幫助包含幾個使用證書指紋的示例,以及如何將其應用於'-Certificate' – Matt 2014-10-08 12:29:39

回答

0

最近,我需要做的這,您需要實際獲取或構建一個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) 
0

一個有些什麼簡單的解決方法就是使用這樣的:

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

假設證書在LocalMachine \ My中。

相關問題