Solved

modify a powershell command get-childitem

Posted on 2013-01-25
5
418 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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