简体   繁体   English

未指定Azure PowerShell证书

[英]Azure PowerShell certificate not specified

I am trying to stop or start a Azure Virtual Machine with PowerShell. 我正在尝试使用PowerShell停止或启动Azure虚拟机。 I am not very experienced in PowerShell so I wrote a simple script as a test: 我对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

I created a .cer certificate on my pc which I exported and then imported in Azure (I used the exact example from http://msdn.microsoft.com/en-us/library/windowsazure/gg551722.aspx ). 我在PC上创建了一个.cer证书,然后将其导出并导入到Azure中(我使用了http://msdn.microsoft.com/zh-cn/library/windowsazure/gg551722.aspx中的确切示例)。 When I Write-Host the $myCert variable I get a response: 当我写主机$ myCert变量时,我得到一个响应:

[Subject] CN=testAzure [主题] CN = testAzure

[Issuer] CN=testAzure [发行方] CN = testAzure

[Serial Number] --serialnumber-- [序列号] --serialnumber--

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

[Not After] 1-1-2040 00:59:59 [不之后] 1-1-2040 00:59:59

[Thumbprint] --thumbprint-- [缩略图]-缩略图-

When I run the script I get the following error: 运行脚本时,出现以下错误:

Get-AzureSubscription : You MUST specify a certificate. Get-AzureSubscription:您必须指定一个证书。 Call Set-AzureSubscription and Select-AzureSubscription first. 首先调用Set-AzureSubscription和Select-AzureSubscription。 At D:\\Users\\foobar\\Desktop\\test.ps1:23 char:1 + Get-AzureSubscription -Current + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Get-AzureSubscription], ArgumentException + FullyQualifiedErrorId : Microsoft.WindowsAzure.Management.Subscription.GetAzureSubscriptionCommand 在D:\\ Users \\ foobar \\ Desktop \\ test.ps1:23 char:1 + Get-AzureSubscription -Current + ~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~ + CategoryInfo:CloseError:(:) [Get-AzureSubscription],ArgumentException + FullyQualifiedErrorId:Microsoft.WindowsAzure.Management.Subscription.GetAzureSubscriptionCommand

I cannot figure out what I am doing wrong? 我不知道自己在做什么错? Does anyone has a suggestion? 有人有建议吗?

Looks like a typo in your code: 看起来像是您的代码中的错字:

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

You're specifying certificate variable in Set-AzureSubscription as $myCer where as the variable above is defined as $myCert (missing "t"). 您在Set-AzureSubscription证书变量指定为$myCer ,其中上述变量定义为$myCert (缺少“ t”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM