Solved

Powershell script to make a list of all directory paths that end in \bad

Posted on 2014-03-13
9
373 Views
Last Modified: 2014-03-13
I need a list of directory paths that start c:\t2\   and end in   \bad  with varying folder structure. I tried this but it does not work.

 Set-Location C:\T2\postoffices
Get-ChildItem . | where{$_.Psiscontainer} -eq "C:\T2\postoffices\*\bad" | select name >> c:\list.txt
0
Comment
Question by:jimmylew52
  • 4
  • 3
  • 2
9 Comments
 
LVL 28

Expert Comment

by:becraig
Comment Utility
Try this:

 Set-Location C:\T2\postoffices
Get-ChildItem . | where{$_.Psiscontainer} | ? {$_.Fullname -like "C:\T2\postoffices\*\bad" } | select name >> c:\list.txt
0
 
LVL 1

Author Comment

by:jimmylew52
Comment Utility
errors saying Where is an invalid argument
0
 
LVL 4

Expert Comment

by:Jason Ryberg
Comment Utility
Really seems like you're overcomplicating your script.  Try this instead:


$BadDirs = Get-ChildItem C:\T2 -Recurse | ? { $_.name -eq "bad" }
$BadDirs | Export-CSV C:\baddirs.csv

Open in new window

0
 
LVL 1

Author Comment

by:jimmylew52
Comment Utility
Works but I need the output to to be similar to

C:\t2\XXXXX\bad

so I can compare to an existing file and add the path if it does not exist. I am sure I will have questions about that also. :-)
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 28

Expert Comment

by:becraig
Comment Utility
$folders = Get-ChildItem C:\T2\postoffices -recurse | ? {$_.Psiscontainer} | ? {$_.Fullname -like "*\bad" } | select Fullname
$folders | out-file c:\list.txt 

Open in new window

0
 
LVL 4

Assisted Solution

by:Jason Ryberg
Jason Ryberg earned 250 total points
Comment Utility
Change the script to:

$BadDirs = Get-ChildItem C:\T2 -Recurse | ? { $_.name -eq "bad" } | Select Fullname
$BadDirs | Export-CSV C:\baddirs.csv

Open in new window

0
 
LVL 1

Author Comment

by:jimmylew52
Comment Utility
both work but give me a header:

FullName                                                                      
--------        

This wil be a problem when  comparing to the existing file I think.
0
 
LVL 28

Accepted Solution

by:
becraig earned 250 total points
Comment Utility
$BadDirs = Get-ChildItem C:\T2 -Recurse | ? { $_.name -eq "bad" } | Select  -expa Fullname
$BadDirs | Export-CSV C:\baddirs.csv
0
 
LVL 1

Author Closing Comment

by:jimmylew52
Comment Utility
Thank so much.  This will save a ton of time in the future. On to the next problem.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

15 Experts available now in Live!

Get 1:1 Help Now