【发布时间】:2014-12-10 16:18:41
【问题描述】:
我有两个 csv 列,我需要比较这两列并将结果写入第三列(Result)。
"行","路径","结果"
"RETENTION_LEVEL 3 1 1 1 1 1 1 1 1 1","C:\Veritas\NetBackup\db\class\policy-v-\schedule\cum\info",
如何使第三列的变量可设置?
#Write retention and policy in a csv file.
$file="C:\Users\toto\schedules.csv"
#Write analysis results in a final csv.
$finalFile="C:\Users\toto\bad_retention.csv"
#query to find information based on the retention level and policy + export in the csv
$find=Get-ChildItem "C:\Veritas\NetBackup\db\class\" -recurse | Select-String -pattern "RETENTION_LEVEL" | Select line,path,@{Expression={$_.result};Label="Result";} | Export-CSV $file –NoTypeInformation
(Import-Csv $file -Delimiter ',')
ForEach-Object{
if(($_.line -match "RETENTION_LEVEL 1 1 1 1 1 1 1 1 1 1") -and ($_.path -match "-v-"))
{
$_.result="BAD RETENTION"
echo $_result;
}
else
{
$_.result="OK";
echo $_result;
}
} | Export-CSV $finalFile –NoTypeInformation
Property 'result' cannot be found on this object; make sure it exists and is settable. At C:\Users\toto\Documents\bad_retention.ps1:28 char:17 + $_. <<<< result="OK"; + CategoryInfo : InvalidOperation: (result:String) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
【问题讨论】:
标签: powershell csv compare