0
votes

I want to create a backup my azure server daily...

for that I am using this link:

  1. https://gallery.technet.microsoft.com/scriptcenter/Back-up-an-Azure-VM-using-9545f0a1#content

  2. http://blogs.technet.com/b/cbernier/archive/2014/04/08/microsoft-azure-automation.aspx

I have created one automation "knsazureautomation" in that I have manually created 1 runbook "knsremotepscommand" and I have imported two files:

  1. Connect-Azure:/scriptcenter/Connect-to-an-Azure-f27a81bb - download this script
  2. Connect-AzureVM: /scriptcenter/Connect-to-an-Azure-85f0782c - download this script

and for workflow for knsremotepscommand (>Author>Draft)

workflow knsremotepscommand
{
    Param
    (
        [parameter(Mandatory=$true)]
        [String]
        $AzureSubscriptionName,

        [parameter(Mandatory=$true)]
        [PSCredential]
        $AzureOrgIdCredential,

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

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

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

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

    # Get credentials to Azure VM
    $Credential = Get-AutomationPSCredential -Name $VMCredentialName     
    if ($Credential -eq $null)
    {
        throw "Could not retrieve '$VMCredentialName' credential asset. Check that you created this asset in the Automation service."
    }      

    # Set up Azure connection by calling the Connect-Azure runbook. You should call this runbook after
    # every CheckPoint-WorkFlow to ensure that the management certificate is available if this runbook
    # gets interrupted and starts from the last checkpoint
    $Uri = Connect-AzureVM -AzureSubscriptionName $AzureSubscriptionName -AzureOrgIdCredential $AzureOrgIdCredential -ServiceName $ServiceName -VMName $VMName  

    # Run a command on the Azure VM
    $PSCommandResult = InlineScript {         
        Invoke-command -ConnectionUri $Using:Uri -credential $Using:Credential -ScriptBlock {
            Invoke-Expression $Args[0]
        } -Args $Using:PSCommand

    }

    $PSCommandResult


}

and created assests are

  1. Create Automation:

    Account Name: KNSAzureAutomation
    Region:EAST US 2
    
  2. Assests:

    1. ADD CONNECTION

      Configure connection
      CONNECTION TYPE:azure
      NAME: KNSAzureConnection
      AUTOMATIONCERTIFICATENAME:KNSAzureCertificationName
      SUBSCRIPTIONID: (my azure subscrption id is given)
      
    2. ADD CREDENTIAL

      CREDENTIAL TYPE:WindowsPowerShell Credential
      NAME:KNSAzureCredential
      
    3. ADD SCHEDULE

      Configure Schedule
      NAME:KnsAzureBackup1
      DESCRIPTION: first backuschedule everaday at 12.45
      
      SELECTED RUNBOOK
      KNSremotePScommand
      AZUREORGIDCREDENTIAL:[email protected]
      AZURESUBSCRIPTIONNAME:BizSpark
      PSCOMMAND:ipconfig/all
      SERVICENAME:KNSWin
      VMCREDENTIALNAME:KNSAzureCredential(Asset Credential name)
      VMNAME:knsazurewin1
      

I am getting this error:

Credential with name '[email protected]' not found for account '3c2455db-035a-477c-b20c-51fd74a586fa'.

If I change the credential of

AZUREORGIDCREDENTIAL:[email protected]

to

AZUREORGIDCREDENTIAL:KNSAzureCredential

I am getting this error:

4/22/2015 4:53:11 PM, Error: Add-AzureAccount : -Credential parameter can only be used with Organization ID credentials. For more information,
please refer to  for more information about the difference
between an organizational account and a Microsoft account.
At Connect-AzureVM:24 char:24
+
    + CategoryInfo          : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount

4/22/2015 4:53:12 PM, Error: Select-AzureSubscription : The subscription name BizSpark doesn't exist.
Parameter name: name
At Connect-AzureVM:27 char:27
+
    + CategoryInfo          : CloseError: (:) [Select-AzureSubscription], ArgumentException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.SelectAzureSubscriptionCommand

4/22/2015 4:53:17 PM, Error: Get-AzureVM : No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to
set the default subscription.
At Connect-AzureVM:29 char:29
+
    + CategoryInfo          : CloseError: (:) [Get-AzureVM], ApplicationException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureVMCommand

4/22/2015 4:53:17 PM, Error: Get-AzureCertificate : Cannot validate argument on parameter 'Thumbprint'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At Connect-AzureVM:29 char:29
+
    + CategoryInfo          : InvalidData: (:) [Get-AzureCertificate], ParameterBindingValidationException
    + FullyQualifiedErrorId :
ParameterArgumentValidationError,Microsoft.WindowsAzure.Commands.ServiceManagement.Certificates.GetAzureCertificate

4/22/2015 4:53:17 PM, Error: Get-AzureWinRMUri : No default subscription has been designated. Use Select-AzureSubscription -Default
<subscriptionName> to set the default subscription.
At Connect-AzureVM:29 char:29
+
    + CategoryInfo          : CloseError: (:) [Get-AzureWinRMUri], ApplicationException
    + FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.GetAzureWinRMUri

4/22/2015 4:53:17 PM, Error: Invoke-Command : Cannot validate argument on parameter 'ConnectionUri'. The argument is null, empty, or an element of
the argument collection contains a null value. Supply a collection that does not contain any null values and then try
the command again.
At knsremotepscommand:92 char:92
+
    + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
2
I responded to this question here: social.msdn.microsoft.com/Forums/en-US/…Joe

2 Answers

0
votes

As the first error says, you need to use an Azure AD credential to authenticate to Azure from your runbook, not a Microsoft account credential. See http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/ for more details on how to create an Azure AD OrgID credential.

The other errors are due to the first error.

0
votes

I would suggest you few things-

a. Most imp- Go to ASSET tab and add proper windows powershell credentials (simply you can use username and password, the same you use to login to azure portal).

b. Add your code in the runbook. Suppose your powershell automation credential name is Backup and your subscription name is xxx. In this case the workflow will be-

workflow Backup 
{
$Cred = Get-AutomationPSCredential -Name
StartVM' Add-AzureAccount -Credential $Cred
Select-AzureSubscription -SubscriptionName “xxx”
inlineScript
{
  # YOUR BACK UP CODE HERE
}
}

c. After this you can schedule your runbook as per your need.

Hope this one will help you-

http://azure.microsoft.com/blog/2014/11/25/introducing-the-azure-automation-script-converter/ http://azure.microsoft.com/en-us/documentation/articles/automation-create-runbook-from-samples/

Thanks.