Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 429
  • Last Modified:

modify a powershell command get-childitem

Hello,

How to change this powershell command to exclude directories containing files flag.txt ?

$folders=Get-ChildItem  | Foreach-Object { Get-ChildItem $_ | Where-Object {$_.psiscontainer}} | % { "$($_.fullname)"}|  Sort-Object -descending

Thanks

bibi
0
bibi92
Asked:
bibi92
  • 3
  • 2
1 Solution
 
SubsunCommented:
Try.. You may remove the -Recurse if required, so it will not search the sub directories..
$folders = Get-ChildItem -Recurse |?{$_.psiscontainer} | % {If ((GCI "$($_.fullname)\*" -Include "flag.txt") -eq $null){$_.fullname}}

Open in new window

0
 
bibi92Author Commented:
Thanks, it takes too much time
0
 
SubsunCommented:
If you want to do recursive search in directory then it will take time depends on the file count...
0
 
bibi92Author Commented:
Exactly thanks
0
 
bibi92Author Commented:
Thanks
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now