Reputation: 599
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
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:
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