0

new to PowerShell here, learning a lot from google, etc.

This is the CSV

I'm trying to write a loop that catches all "Employee_Name" that are stated as null and "Revoked" under the "Approval" column and puts them into a Variable.

I know there is probably an easy solution for that, but I could find anything on the web regarding multiple-value queries.

this is my code:

$ListDataCollection = Import-Csv -Path "C:\Temp\FinalListData.csv"

$users_to_disable = @();

$ListDataCollection | ForEach-Object {
if ([string]::IsNullOrEmpty($_.Approval)) {
    $users_to_disable += $_.Employee_Name
}
if ($_.Approval -eq "Revoke") {
    $users_to_disable += $_.Employee_Name
 }
}

$users_to_disable

and when I try to run it, the result is empty. it just shows the variable I'm using and not showing any data.

  • Just: `if(!$_.Approval) { ... } elseif ($_.Approval -eq "Revoke") { ... }` or `if(!$_.Approval -or $_.Approval -eq "Revoke") { ... }`, as an aside, [Try to I avoid using the increase assignment operator (+=) to create a collection](https://stackoverflow.com/a/60708579/1701026) as it might get very expensive. – iRon Nov 16 '22 at 08:55

1 Answers1

0

Solved it! the file I created "FinalListData.csv" was corrupt because I just changed the extension to CSV from XLSX when creating it. and PowerShell wasn't able to read it that way.