Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-13
9
Medium Priority
?
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 39927825
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
ID: 39927837
errors saying Where is an invalid argument
0
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39927840
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:jimmylew52
ID: 39927847
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
 
LVL 29

Expert Comment

by:becraig
ID: 39927859
$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 1000 total points
ID: 39927863
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
ID: 39927879
both work but give me a header:

FullName                                                                      
--------        

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

Accepted Solution

by:
becraig earned 1000 total points
ID: 39927882
$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
ID: 39927887
Thank so much.  This will save a ton of time in the future. On to the next problem.
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

636 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