1

Validate Status Column using powershell. If any status column contain Not-compliant then overall status column needs to be displayed not-compliant. Attached data for your reference.

Trying below code but not getting expected output.

$csv = Import-Csv -Path C:\Users\Desktop\DDPC1.csv

$csv | ForEach-Object {
    if ($_.Status -eq "Not-Compliant") {
        Echo "The system is $($_.Status) in $($_.Parameter)"
    }else
    {Write-Host "System is Fully compliant in All Parameter"
    }
}

In Case of multiple parameter non-compliant, output needs to be The system is Not-Compliant in Patching and GoogleChrome. But Getting below output.

System is Fully compliant in All Parameter

The system is Not-Compliant in Patching

The system is Not-Compliant in Chrome

System is Fully compliant in All Parameter

In Case of compliant, output needs to be The system is Fully Compliant in all parameter. But Getting below output.

System is Fully compliant in All Parameter

System is Fully compliant in All Parameter

System is Fully compliant in All Parameter

System is Fully compliant in All Parameter

CSV Data: -

Parameter Version Status
Windows 11 20H2 Compliant
Patching NA Not-Compliant
Chrome 10.1 Not-Compliant
Overall NA
1
  • @VomitIT-ChunkyMessStyle Actual issue remains same. Commented Dec 5, 2022 at 0:52

1 Answer 1

1

Based on the sample data, the overall data/row doesn't seem to fit into the csv to correlate correctly. Using logic to omit it explicitly seems to make better sense to wrap additional logic to get what you prefer per example output.

Use arrays and counts along with some math around those counts for the conditions and omit the overall row to simplify a bit to get the exact results you seek.

PowerShell

$csv = Import-Csv -Path C:\Users\Desktop\DDPC1.csv;
$cnt = ($csv | ? { $_.Parameter -ne "Overall"}).Count
[array]$noncompliant = $csv | ? { $_.Parameter -ne "Overall"-and $_.Status -eq "Not-Compliant"};
[array]$compliant = $csv | ? { $_.Parameter -ne "Overall"-and $_.Status -eq "Compliant"};
$noncompliant | ForEach-Object {"The system is $($_.Status) in $($_.Parameter)"};
$compliant | ForEach-Object {"The system is $($_.Status) in $($_.Parameter)"};
If($noncompliant.Count -eq 0 -and $compliant.Count -eq $cnt) {"The system is Fully Compliant in all parameter"} Else {"The system is Not-Compliant"};

Supporting Resources

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .