Solved

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

Posted on 2014-03-13
9
399 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
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
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 Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
powershell mailbox move question 8 49
Powershell and ConvertTo-HTML 5 38
Group Members to a csv file using PowerShell. 7 41
Error when Running powershell script 6 31
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
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…

749 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