Thanks ahead of time. I'm trying to import multiple .csv files, add a column to them, then write to that column based on the value of another column
What I'm trying to do is follow this logic:
- Loop through CSVs
- For each CSV:
- Add a new column
- Look for some words.
- If you see the words, write a different word in the new column
- End loop
- End loop
My code is here:
Function getTag ([string]$vuln){
if($vuln -like "adobe-apsb-")
{return "Adobe Flash"}
if($vuln -like "jre-")
{return "Java"}
else
{return "No vulnerability code available"}
}
$in = "D:\Splunk\Inbound"
$out = 'D:\Splunk\Outbound'
Get-ChildItem $in -Filter *.csv |
ForEach-Object{
Import-Csv $_ | Select-Object *,@{Name='Tag';Expression={getTag $_.'Vulnerability ID'}} | Export-Csv $_.Name
}
Right now, $_ is coming through as a string, not a CSV, and I believe that's my problem. Does anyone have a good way to access that csv file from inside the nested loop?
Import-Csv $_.FullName?