praveen gogula
praveen gogula

Reputation: 599

exception:"Cannot find the 'Connect-AzureVM' command"

I'm trying to "BackUp Azure VM" by taking Azure Runbook named "Back up an Azure VM using Microsoft Azure Automation" from the gallery. But while testing it throws an exception as below "exception : At line:75 char:8 + $Uri = Connect-AzureVM -AzureConnectionName $AzureConnectionName -serviceName $S ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cannot find the 'Connect-AzureVM' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { Connect-AzureVM }'". So any one from the other end help me out. Thank You.

Upvotes: 2

Views: 1636

Answers (1)

praveen gogula
praveen gogula

Reputation: 599

At first take the "Connect-AzureVM" runbook from the gallery and publish it... Then you will get another exception:

At line:159 char:8 + $Uri = Connect-AzureVM -AzureConnectionName $AzureConnectionName -serviceName $S ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Could not find a parameter named 'AzureConnectionName'. " The Exception can be removed by following the below steps:

It looks like the "BackupAzureVM" uses an outdated version of this runbook.

To make the updates:

  1. Edit the BackupAzureVM runbook
  2. Replace the $AzureConnectionName parameter with $AzureAdOrgIdName parameter
  3. Retrieve your Azure OrgID from the Asset store
  4. Click Insert > Runbook > Connect-AzureVM to get the correct parameters to pull the $URI and update the variables (this replaces the existing Connect-AzureVM call). The correct parameters will be included.

Here is an example of an updated version of the BackupAzureVM following the steps above:

workflow BackupAzureVM
{
Param
(
[parameter(Mandatory=$true)]
[String]
$AzureOrgIdCredentialName,

[parameter(Mandatory=$true)]
[String]
$ServiceName,

[parameter(Mandatory=$true)]
[String]
$VMName,

[parameter(Mandatory=$true)]
[String]
$StorageAccountName,

[parameter(Mandatory=$true)]
[String]
$backupContainerName

)

$Cred = Get-AutomationPSCredential -Name $AzureOrgIdCredentialName
$Uri = Connect-AzureVM ` -AzureOrgIdCredential $Cred ` -     AzureSubscriptionName "MySubscription" ` -ServiceName $ServiceName ` -VMName    $VMName

// Stop Azure VM

Stop-AzureVM -ServiceName $ServiceName -Name $VMName –StayProvisioned

// Backup Azure VM

 Backup-AzureVM -serviceName $ServiceName -VMName $VMName -backupContainerName $backupContainerName -backupStorageAccountName $StorageAccountName –includeDataDisks

// Start Azure VM

Start-AzureVM -ServiceName $ServiceName -Name $VMName

}

Upvotes: 3

Related Questions