Powershell:工作流无法使用递归

时间:2018-07-19 07:21:55

标签: powershell azure-powershell

我正在尝试为Azure虚拟机备份生成备份报告。

我有很多订阅,每个订阅都有超过50个RG。我们的环境中托管了将近1500个虚拟机。

我尝试生成备份报告,但是PowerShell脚本花费了2个小时来完成。所以我正在尝试一些并行处理的工作流。

但是我在这里看不到任何递归调用,但出现了以下错误。

System.Management.Automation.ParseException: At line:1 char:1
+ try
+ ~~~
A workflow cannot use recursion.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
try
{
    #$cred = Get-Credential
    Login-AzureRmAccount #-Credential $cred

    $tempCSVPath = Read-Host 'Please provide local path to store the report, Example- D:\temp\report.csv  '

    $Path = 'C:\AzureRmProfile.json'

    $subs = Get-AzureRmSubscription

    Get-AzureRmRecoveryServicesVault

    foreach($sub in $subs)
    {
        if($sub.Name -ne 'IRMLAB')
        {
            Select-AzureRmSubscription -SubscriptionName $sub.Name
            $Vms = @()
            $RR = @()
            $rms = Get-AzureRmRecoveryServicesVault

            Foreach($rm in $rms)
            {
                Set-AzureRmRecoveryServicesVaultContext -Vault $rm

                $container_list = Get-AzureRmRecoveryServicesBackupContainer -ContainerType AzureVM

                Workflow a{
                    param (
                        [parameter(Mandatory=$true)]
                        [psobject]$AzureRmConObject,
                        [parameter(Mandatory=$true)]
                        [psobject]$ProfilePath
                    )

                    foreach -parallel($container_list_iterator in $AzureRmConObject)
                    {
                        $Profile = Select-AzureRmProfile -Path $ProfilePath
                        $backup_item = Get-AzureRmRecoveryServicesBackupItem -Container $container_list_iterator -WorkloadType AzureVM
                        $backup_item_array = ($backup_item.ContainerName).split(';')

                        $Vms += [pscustomobject]@{
                            Virtualmachine_name = $backup_item_array[2]
                            Vault_resourcegroup_name = $backup_item_array[1]

                            backup_item_last_backup_status = $backup_item.LastBackupStatus
                            backup_item_latest_recovery_point = $backup_item.LatestRecoveryPoint
                        }
                    }

                    a -AzureRmConObject $container_list -ProfilePath $Path
                    $Vms | Export-Csv -Path $tempCSVPath -Append -Force
                }
            }
        }
    }
}
catch
{
    Write-Host $_.Exception
}

1 个答案:

答案 0 :(得分:0)

似乎在工作流中不允许调用递归函数。请参阅此处-> Docs