Solved

modify a powershell command get-childitem

Posted on 2013-01-25
5
416 Views
Last Modified: 2013-01-28
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
Comment
Question by:bibi92
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38820187
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
 

Author Comment

by:bibi92
ID: 38826355
Thanks, it takes too much time
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38826384
If you want to do recursive search in directory then it will take time depends on the file count...
0
 

Author Comment

by:bibi92
ID: 38826401
Exactly thanks
0
 

Author Closing Comment

by:bibi92
ID: 38826402
Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article will help you understand what HashTables are and how to use them in PowerShell.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now