Alok Maheshwari
Alok Maheshwari

Reputation: 39

Trying to Exclude a Folder with -Recursive search in get-childitem

I am new to PowerShell...

SL D:\SomeFolder get-childitem -exclude <D:\Somefolder\A> -recurse -Directory

I don't want d:\somefolder\A and its contents in the results, but for rest of the directories in "somefolder" I want recursive results.

I tried the command above, however, it is going inside the "\A" directory. It may be happening due to the -recurse switch, because if I don't use it...

Is there another way to achieve this?

Upvotes: 3

Views: 1227

Answers (1)

Anton Krouglov
Anton Krouglov

Reputation: 3399

This lists children folders of D:\SomeFolder without D:\Somefolder\A:

get-childitem 'D:\SomeFolder' -recurse -Directory ` 
  | ? { $_.FullName -notlike 'D:\Somefolder\A*' }

See also here

Upvotes: 3

Related Questions