【问题标题】:Azure PowerShell certificate not specified未指定 Azure PowerShell 证书
【发布时间】:2013-06-27 08:59:58
【问题描述】:

我正在尝试使用 PowerShell 停止或启动 Azure 虚拟机。我对PowerShell不是很有经验,所以我写了一个简单的脚本作为测试:

Import-Module "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"

$subID = "<GUID>"
$thumbprint = "<Thumbprint>"
$subscriptionName = "testAzure"
$myCert = Get-Item cert:\\CurrentUser\My\$thumbprint
$vmName = "<vm name>"

Set-AzureSubscription –SubscriptionName $subscriptionName -SubscriptionId $subID -Certificate $myCer
Select-AzureSubscription -SubscriptionName $subscriptionName

Get-AzureSubscription -Current

我在我的电脑上创建了一个 .cer 证书,我将其导出然后导入 Azure(我使用了来自 http://msdn.microsoft.com/en-us/library/windowsazure/gg551722.aspx 的确切示例)。当我写托管 $myCert 变量时,我得到一个响应:

[主题] CN=testAzure

[发行人] CN=testAzure

[序列号]--序列号--

[不是之前] 29-6-2013 15:27:26

[不在之后] 1-1-2040 00:59:59

[指纹] --thumbprint--

当我运行脚本时,出现以下错误:

Get-AzureSubscription :您必须指定证书。称呼 首先设置-AzureSubscription 和 Select-AzureSubscription。在 D:\Users\foobar\Desktop\test.ps1:23 char:1 + 获取 AzureSubscription -Current + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzureSubscription], ArgumentException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.Subscription.GetAzureSubscriptionCommand

我无法弄清楚我做错了什么?有人有建议吗?

【问题讨论】:

    标签: powershell azure virtual-machine


    【解决方案1】:

    您的代码中似乎有错字:

    Set-AzureSubscription –SubscriptionName $subscriptionName -SubscriptionId $subID -Certificate $myCer
    

    您将 Set-AzureSubscription 中的证书变量指定为 $myCer,其中上述变量定义为 $myCert(缺少“t”)。

    【讨论】:

    • Set-StrictMode -Version Latest 是你的朋友。养成将它作为所有脚本的第一行的习惯。
    • 哈哈,天哪,我已经为此苦苦挣扎了好几个小时。谢谢 Gaurav Mantri
    猜你喜欢
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-02-07
    • 2019-02-28
    • 2018-01-26
    • 1970-01-01
    • 2021-06-13
    • 2012-03-24
    相关资源
    最近更新 更多