Forum Discussion
rexParthi
Aug 16, 2023Copper Contributor
I am unable to add multiple condition ps where-object
I am unable to add multiple condition where-object, getting error when add -and condition
The below one works
foreach($l in (gci -Path .\ -Filter *.xlsx))
{
if (
(Import-Excel -Path $l.Name|Where-Object message_id -EQ '491582638558019584').count -gt 0)
{Write-Host $l.Name}
}
and this one did not work, and this dosn't give any output
foreach($l in (gci -Path .\ -Filter 345-ASSIGNMENT_NOT_COMPLETED*.xlsx)){
if ( (Import-Excel -Path $l.Name|Where-Object ($_.message_id -EQ '491582638558019584' -and $_.action -eq 'delete') ).count -gt 0)
{Write-Host $l.Name}
}
can anyone help me on this?
1 Reply
Sort By
- rexParthiCopper Contributor
I got the issue
it is becase of the () in the where condition it should be {} to use -and for adding different propertyforeach($l in (gci -Path .\ -Filter 345-ASSIGNMENT_NOT_COMPLETED*.xlsx)){ if ( (Import-Excel -Path $l.Name|Where-Object {$_.message_id -EQ '491582638558019584' -and $_.action -eq 'delete'} ).count -gt 0) {Write-Host $l.Name} }