Hello,
I would like some help with a powershell script that extracts names from a CSV file based on particular criteria.
$TargetLabels = @("Select the operatives -")
$a = Import-Csv D:\source.csv
$a | % -begin{$rec=@(); $o=@{}} `
-process{ `
if ($_.label -eq "End of Site Details") {
if ($o.count -ne 0) {
$rec += new-object -TypeName psobject -Property $o
$o=@{}
}
}
if ($TargetLabels -contains $_.label){
$o += @{$_.label=$_.response}
}
}
#add the one we were constructing
$rec += new-object -TypeName psobject -Property $o
$rec | Export-Csv -Path D:\iauditor_exports_folder\DailyWorksheets\Output\DataNames.txt -NoTypeInformation
Open in new window
In the source file it is extracting the names in the row where 'Select the operatives -' appears
On initial testing it is extracting names on every row but it misses the row where the names 'Wayne Pepperpot, Graham Prickstick'
Any ideas?
Names in the source file are made up