我正在检索 Azure 数据工厂日志以使用 Powershell 进行分析。
我正在成功检索顶级日志(管道)和嵌套在其中的日志(活动)并写入文本文件。
但是,我在展平活动文件时遇到问题,该文件由平面记录和包含 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 和脚本的示例,但我还不想去那里 - 我只想了解如何执行此操作。