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.
2
votes
It's possible that the PowerShell commands have been deprecated or renamed... where is the link to the run book you're trying to use?
- Jeff Wilcox
thats for your quick response, I get that runbook from the runbook Gallery of Azure..
- praveen gogula
Thanks, I got the result
- praveen gogula
Reff Link: gallery.technet.microsoft.com/scriptcenter/…
- praveen gogula
1 Answers
3
votes
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:
- Edit the BackupAzureVM runbook
- Replace the $AzureConnectionName parameter with $AzureAdOrgIdName parameter
- Retrieve your Azure OrgID from the Asset store
- 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
}