Question : How do I use the "-and" logical operator in PowerShell?

Hi all,

The first code snippet below works fine.  As you can see it makes use of the logical operator -and to test a couple of different cases.  All the relevant articles I've found about PowerShell say that -and is the logical AND operator - ok that makes sense.

The second code snippet does NOT work.  When I run it PowerShell says:

Test-Path : A parameter cannot be found that matches parameter name 'and'.
At xxx\ArchiveData.ps1:38 char:6
+     -and  <<<< Test-Path($LogsFolder) `

My basic question is ... WTF?  -and is definitely a value logical operator - I assume I'm using it incorrectly although I can't see where.  Unfortunately Google searches containing "-and" don't return a whole lot because of how their operators work ...  Is the -and operator only value on Where-Object clauses?

Can anyone point out what the obvious thing is that I'm missing?  I'm sure it's obvious but I need a 2nd(/3rd/4th/5th) pair of eyes.  :)

Thanks!
Chris
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
foreach ($Folder in Get-ChildItem -Path $Current | Where-Object { `
   $_.lastwritetime -lt $LatestDate `
   -and $_.mode -Match "d" `
   -and $_.ToString().ToUpper() -ine "LOGFILES" `
   })
 
--- end first code snippet ---
 
if (Test-Path($Folder) `
   -and Test-Path($LogsFolder) `
   -and Test-Path($DataListHeader) `
   -and Test-Path($DataListFooter))
Open in New Window Select All

Answer : How do I use the "-and" logical operator in PowerShell?

Solution below.

Just moved the parentheses around a bit ...
1:
2:
3:
4:
if ((Test-Path($Folder)) `
   -and (Test-Path($LogsFolder)) `
   -and (Test-Path($DataListHeader)) `
   -and (Test-Path($DataListFooter)))
Open in New Window Select All
Random Solutions  
 
programming4us programming4us