0

我想每天为我的天蓝色服务器创建一个备份...

为此,我正在使用此链接:

  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

我创建了一个自动化“knsazureautomation”,其中我手动创建了 1 个运行手册“knsremotepscommand”,并导入了两个文件:

  1. Connect-Azure:/scriptcenter/Connect-to-an-Azure-f27a81bb - 下载此脚本
  2. Connect-AzureVM:/scriptcenter/Connect-to-an-Azure-85f0782c - 下载此脚本

和 knsremotepscommand 的工作流程(>作者>草稿)

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


}

和创建的资产是

  1. 创建自动化:

    Account Name: KNSAzureAutomation
    Region:EAST US 2
    
  2. 评估:

    1. 添加连接

      Configure connection
      CONNECTION TYPE:azure
      NAME: KNSAzureConnection
      AUTOMATIONCERTIFICATENAME:KNSAzureCertificationName
      SUBSCRIPTIONID: (my azure subscrption id is given)
      
    2. 添加凭据

      CREDENTIAL TYPE:WindowsPowerShell Credential
      NAME:KNSAzureCredential
      
    3. 添加时间表

      Configure Schedule
      NAME:KnsAzureBackup1
      DESCRIPTION: first backuschedule everaday at 12.45
      
      SELECTED RUNBOOK
      KNSremotePScommand
      AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com
      AZURESUBSCRIPTIONNAME:BizSpark
      PSCOMMAND:ipconfig/all
      SERVICENAME:KNSWin
      VMCREDENTIALNAME:KNSAzureCredential(Asset Credential name)
      VMNAME:knsazurewin1
      

我收到此错误:

找不到帐户“3c2455db-035a-477c-b20c-51fd74a586fa”的名称为“vnalluri2006@hotmail.com”的凭据。

如果我更改凭据

AZUREORGIDCREDENTIAL:vnalluri2006@hotmail.com

AZUREORGIDCREDENTIAL:KNSAzureCredential

我收到此错误:

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
4

2 回答 2

0

我会建议你几件事-

一个。大多数 imp- 转到资产选项卡并添加正确的 windows powershell 凭据(只需使用用户名和密码,与登录 azure 门户相同)。

湾。在 Runbook 中添加您的代码。假设您的 powershell 自动化凭证名称是 Backup,您的订阅名称是 xxx。在这种情况下,工作流程将是 -

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

C。在此之后,您可以根据需要安排运行手册。

希望这个对你有帮助-

http://azure.microsoft.com/blog/2014/11/25/introducing-the-azure-automation-script-converter/ http://azure.microsoft.com/en-us/documentation/articles/automation-从样本创建运行手册/

谢谢。

于 2015-04-22T12:43:09.510 回答
0

正如第一个错误所说,您需要使用 Azure AD 凭据从 Runbook 向 Azure 进行身份验证,而不是 Microsoft 帐户凭据。有关如何创建 Azure AD OrgID 凭据的更多详细信息,请参阅http://azure.microsoft.com/blog/2014/08/27/azure-automation-authenticating-to-azure-using-azure-active-directory/ 。

其他错误是由于第一个错误。

于 2015-04-22T19:29:51.133 回答