Solved

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

Posted on 2014-03-13
9
387 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 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
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.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Set OWA language and time zone in Exchange for individuals, all users or per database.
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 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