Michael Morgan
Michael Morgan

Reputation: 21

PowerShell: List all items except for certain files

Get-childItem | Where-Object { ($_.CreationTime).ToString('dd/MM/yyyy') -EQ 01/01/2017}

How do you create exceptions when listing files ? So if I want to list every file in a directory apart from files called "File 1" and "File 2"

Upvotes: 0

Views: 1036

Answers (3)

Bill Kindle
Bill Kindle

Reputation: 169

Either of the above examples will work, it's more of a preference. I personally like to do as much filtering of the data before I pass it along the pipeline.

Upvotes: 0

Pramod Maharjan
Pramod Maharjan

Reputation: 171

Get-childItem | Where-Object {$_.Name -ne 'file 1' -and $_.name -ne 'file 2'}

Upvotes: 0

BenH
BenH

Reputation: 10044

Using the -Exclude parameter on Get-ChildItem:

Get-ChildItem -Exclude File1,File2 | Where-Object { ($_.CreationTime).ToString('dd/MM/yyyy') -EQ 01/01/2017}

Upvotes: 2

Related Questions