0

所以这是背景故事,我试图以几种不同的方式验证数据。我查询了一个数据库并将该数据导出到 csv。

然后使用 powershell 我运行以下命令

$staleDates = Import-Csv DataAudit.csv | Where-Object { $_.asOfDate -ne "" } | Foreach-Object { $_.AsOfDate = $_.AsOfDate -as [datetime]; $_ } | Where-Object {$_.asOfDate -lt $measuredDate}

$nullDates = Import-Csv DataAudit.csv | Where-Object {$_.asOfDate -eq ""}

$percentTooLarge = Import-Csv DataAudit.csv | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object { $_.SumHoldingPercent -gt 100 }

$percentTooSmall = Import-Csv DataAudit.csv | Where-Object {$_.SumHoldingPercent -ne "" } | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object {$_.SumHoldingPercent -lt 99.99999 }

有没有办法可以将这 4 个变量的结果组合成一个 csv,然后我可以通过电子邮件将其作为不良数据报告发送出去?

另外,我正在使用 Powershell v1.0

4

1 回答 1

2

以下应该有效:

$badData = Import-Csv DataAudit.csv | Where-Object { $_.asOfDate -ne "" } | Foreach-Object { $_.AsOfDate = $_.AsOfDate -as [datetime]; $_ } | Where-Object {$_.asOfDate -lt $measuredDate}
$badData += Import-Csv DataAudit.csv | Where-Object {$_.asOfDate -eq ""}
$badData += Import-Csv DataAudit.csv | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object { $_.SumHoldingPercent -gt 100 }
$badData += Import-Csv DataAudit.csv | Where-Object {$_.SumHoldingPercent -ne "" } | Foreach-Object { $_.SumHoldingPercent = $_.SumHoldingPercent -as [float]; $_ } | Where-Object {$_.SumHoldingPercent -lt 99.99999 }

$badData | Export-CSV -NoTypeInformation -Path allBadData.csv
于 2012-05-21T17:01:27.103 回答