我正在使用Powershell检索Azure Data Factory日志以进行分析 .

我成功检索顶级日志(管道)和嵌套在(活动)内的日志并写入文本文件 .

但是我有问题展平活动文件,其中包含平面记录和包含json的字段的混合

这是我的删节剧本 . 问题出在最后一个cmdlet调用上 . 我需要弄清楚如何将其展平到我需要的地方

$DateFrom = (new-object System.DateTime 2018, 07, 01)
$DateTo = Get-Date
$Pipeline="MyPipeline"
$Outputfile="C:\SRC\ADF\$Pipeline.TXT"
$OutputSubfile="C:\SRC\ADF\$Pipeline.Sub.TXT"
$DFname ="MyDataFactory"
$RG="MyRG"
$TenantId="a16xxxx-xxx-xxx"
$Subscription="d8xxx-xxx-xxx"

$Credential = Get-Credential

Connect-AzureRmAccount `
-TenantId $TenantId `
-Subscription $Subscription `
-Credential $Credential

$oADFLog = Get-AzureRmDataFactoryV2PipelineRun `
-ResourceGroupName $RG `
-DataFactoryName $DFname `
-LastUpdatedAfter $DateFrom `
-LastUpdatedBefore $DateTo `
-PipelineName $Pipeline

# This is the pipeline log - it works as required
$oADFLog | Export-Csv -Path $Outputfile -Delimiter "`t" -NoTypeInformation

# Delete the subtask file
Remove-Item -Path $oADFSubLog -Force -Recurse -ErrorAction Ignore

Foreach ($PipelineRun IN $oADFLog)
{
    # For each parent run ID, check the child tasks
    # File results in thispart need to be cleaned up
    $oADFSubLog = Get-AzureRmDataFactoryV2ActivityRun `
    -PipelineRunId $PipelineRun.RunId `
    -ResourceGroupName $PipelineRun.ResourceGroupName `
    -DataFactoryName $PipelineRun.DataFactoryName `
    -RunStartedAfter $DateFrom `
    -RunStartedBefore $DateTo

    # This is the activity log - it has nested data types and is ugly
    # I need to flatten the Json inside the message
    $oADFSubLog | Export-Csv -Append -Path $OutputSubfile -Delimiter "`t" -NoTypeInformation
}

鉴于 $oADFSubLog 在上面的脚本中,我发现我可以拿出一些我需要的东西:

(ConvertFrom-Json -InputObject $oADFSubLog[0].Input.ToString()).packageLocation

这从Json中提取了我需要的属性

但我不确定如何轻松地将其与其他平面属性一起推送到文件中

我试过这个,这真的只是在黑暗中刺伤

$oADFSubLog | Select-Object -Property ActivityName,@(ConvertFrom-Json -InputObject $oADFSubLog[0].Input.ToString()).packageLocation

但我明白了

Select-Object:无法将System.Management.Automation.PSObject转换为以下类型之一{System.String,System.Management.Automation.ScriptBlock} .

我已经看到了几个可以添加的自定义cmdlet和脚本示例,但我不想再去那里 - 我只想了解如何执行此操作 .