gpt4 book ai didi

powershell - 未指定 Azure PowerShell 证书

转载 作者:行者123 更新时间:2023-12-03 03:18:35 25 4
gpt4 key购买 nike

我正在尝试使用 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 变量时,我得到响应:

[Subject] CN=testAzure

[Issuer] CN=testAzure

[Serial Number] --serialnumber--

[Not Before] 29-6-2013 15:27:26

[Not After] 1-1-2040 00:59:59

[Thumbprint] --thumbprint--

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

Get-AzureSubscription : You MUST specify a certificate. Call Set-AzureSubscription and Select-AzureSubscription first. At D:\Users\foobar\Desktop\test.ps1:23 char:1 + Get-AzureSubscription -Current + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzureSubscription], ArgumentException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.Subscription.GetAzureSubscriptionCommand

我不知道我做错了什么?有人有建议吗?

最佳答案

您的代码中似乎有一个拼写错误:

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

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

关于powershell - 未指定 Azure PowerShell 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17384155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com