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?