简体   繁体   中英

Azure PowerShell certificate not specified

I am trying to stop or start a Azure Virtual Machine with PowerShell. I am not very experienced in PowerShell so I wrote a simple script as a test:

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 ). When I Write-Host the $myCert variable I get a response:

[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--

When I run the script I get the following error:

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

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").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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