Solved

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

Posted on 2014-03-13
9
409 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 250 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 250 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

687 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