Mar 04 2021 01:19 PM
Hi,
I have the following code.. It runs with no errors but does not give any output:
$rec_cnt = 0
$data_conv = (Get-Content $destFile2)
$result = foreach ($line in $data_conv) {
$line.host
if ($line.IsError -eq " " )
{ $line.IsError = 9 }
if ($line.severity_id_and_name -eq 1 -or $line.severity_id_and_name -eq 2 -or $line.severity_id_and_name -eq 4)
{$line.IsError = 0 }
Else {
if ($line.severity_id_and_name -eq 3)
{ $line.IsError = 1 }
}
$rec_cnt = $rec_cnt + 1
} # close Foreach loop
$result | Set-Content $destFile3
Mar 05 2021 03:43 PM
Hello @campbelm01,
I think the problem you are facing is related to usage of Get-Content cmdlet.
The Get-Content cmdlet gets the content of the item ... for files, the content is read one line at a time and returns a collection of objects, each of which represents a line of content.
Later in your loop you are referring to $line properties but because of Get-Content your $line is a string.
What type of file are you trying to read? Is it csv?
Please try to use Import-Csv.