Home > Mobile >  Powershell if statement into foreach loop from csv
Powershell if statement into foreach loop from csv

Time:09-17

I have created a script to go through a csv file and take the values of each column. Based on one of the values an if statement must be ran and bring back the results. So far it only goes through the if, not the else. Can you help me figure this out? This is the code I have.

$members = import-csv membership.csv
select-object "id","group","operation" |


Foreach ($row in $members) {
    If ($row.operation = "add")

    {write-host "This is IF statement"}

    Else 

    {write-host "This is ELSE statement"}
}

CodePudding user response:

$members = import-csv membership.csv
select-object "id","group","operation" |


Foreach ($row in $members) {
If ($row.operation -eq "add")

{write-host "This is IF statement"}

Else 

{write-host "This is ELSE statement"}

}

  • Related