Hell Everyone
I am very new in powershell. I have a requirement to code some tests in Powershell.
I am trying to validate a CSV file by finding out if there is any text value in my numeric fields.
This is my source data like this
ColA, ColB , ColC , ColD,
23 , 23 , ff , 100,
2.30E+01, 34, 2.40E+01, 23
df , 33 , ss , df
34 , 35 , 36 , 37
Required out put
ColA, ColC, ColD
2.30E+01, ff, df
df, 2.40E+01
, ss
I have tried
cls
function Is-Numeric ($Value) {
return $Value -match "^[\d\.]+$"
}
$arrResult = @()
$arraycol = @()
$FileCol = @("ColA","ColB","ColC","ColD") .. These are some of the specific columns that are numeric in file
$dif_file_path = "C:\Users\$env:username\desktop\f2.csv"
#Importing CSVs
$dif_file = Import-Csv -Path $dif_file_path -Delimiter ","
############## Test Datatype (Is-Numeric)##########
foreach($col in $FileCol)
{
foreach ($line in $dif_file) {
$val = $line.$col
$isnum = Is-Numeric($val)
if ($isnum -eq $false) {
$arrResult += $line.$col
$arraycol += $col
}
}
}
[pscustomobject]@{$arraycol = "$arrResult"}| out-file "C:\Users\$env:username\Desktop\Errors1.csv"
####################
I am not getting proper output as required with this file.
Any help in this regard?
Thanks
I am very new in powershell. I have a requirement to code some tests in Powershell.
I am trying to validate a CSV file by finding out if there is any text value in my numeric fields.
This is my source data like this
ColA, ColB , ColC , ColD,
23 , 23 , ff , 100,
2.30E+01, 34, 2.40E+01, 23
df , 33 , ss , df
34 , 35 , 36 , 37
Required out put
ColA, ColC, ColD
2.30E+01, ff, df
df, 2.40E+01
, ss
I have tried
cls
function Is-Numeric ($Value) {
return $Value -match "^[\d\.]+$"
}
$arrResult = @()
$arraycol = @()
$FileCol = @("ColA","ColB","ColC","ColD") .. These are some of the specific columns that are numeric in file
$dif_file_path = "C:\Users\$env:username\desktop\f2.csv"
#Importing CSVs
$dif_file = Import-Csv -Path $dif_file_path -Delimiter ","
############## Test Datatype (Is-Numeric)##########
foreach($col in $FileCol)
{
foreach ($line in $dif_file) {
$val = $line.$col
$isnum = Is-Numeric($val)
if ($isnum -eq $false) {
$arrResult += $line.$col
$arraycol += $col
}
}
}
[pscustomobject]@{$arraycol = "$arrResult"}| out-file "C:\Users\$env:username\Desktop\Errors1.csv"
####################
I am not getting proper output as required with this file.
Any help in this regard?
Thanks