0

Is there a command that I can run on a windows Server 2008 r2 that will only show directories that contain a certain word.

For Example I want to find all directories that contain "logs"

That means it will return these all locations, since they contain the word "Logs"

C:\Logs
C:\stuff\ServerLogs
C:\example\Logsforapps
Daniel
  • 6,940
  • 6
  • 33
  • 64
Henry
  • 920
  • 1
  • 5
  • 17

4 Answers4

5

In cmd you can do a: dir /a:d /b /s C:\*logs*

Or if you've a recent-ish PowerShell version

Get-ChildItem -Directory -Path C: -Recurse -Filter *logs* | Select-Object FullName
jscott
  • 24,484
  • 8
  • 79
  • 100
3

Powershell can deliver what you're after with the following:

gci -r c:\temp | where {$_.psIsContainer -eq $true -and $_.name -match "logs"} | foreach { $_.fullname }
Clayton
  • 4,523
  • 17
  • 24
  • +1 And may I suggest you try my answer using `dir`, it very much will provide the full path as a side effect of `/b /s`. – jscott Feb 10 '16 at 20:19
  • Oops, sorry. Been so long for batch, though /s was only subdirs, forgot it changed the output format. – Clayton Feb 10 '16 at 20:22
1

Use the File Classification Infrastructure (FCI) tool built in to server 2008+ to query the servers in question for the files with the specific word.

Daniel
  • 6,940
  • 6
  • 33
  • 64
Jim B
  • 24,081
  • 4
  • 36
  • 60
  • 1
    By default File Service manager is not installed. OP asked for a script to run on 500 servers. This wouldn't be a good approach unless all 500 servers had File Services Manager installed. https://technet.microsoft.com/en-us/library/ff627828(v=ws.10).aspx – Murray W Feb 11 '16 at 15:22
  • I believe FCI is only required on one server, but I'll verify – Jim B Feb 11 '16 at 17:26
0

How to find directories with 'log' in them.

  1. Open File Explorer
  2. From the Search upper right corner type keyword filetype:directory

Example: log filetype:directory will return all directories with the word log in it. Remember to select the starting folder. Example: Documents search will return only what was found in the default documents folder. C:\Windows will return everything within the Windows folder. Selecting C:\ drive with Admin privileges should get you everything on the C: drive. If you have multiple drives select "Computer" then search keyword filetype:directory

Updated with simple script.

    Dim objShell
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run ("explorer /root,""search-ms:query=logs&crumb=kind:=folder&crumb=location:&""") 
    Set objShell = Nothing

The above will search all your internal and mapped drives in your explorer.exe view. The location: can be set if you need to check only select drives. It would look like

    location:C:\

You can repeat this for every target drive or folder path you need to search.

    &crumb=location:C:\&crumb=location:F:\directory&crumb=location:G:\

From my testing on 2008 R2 I found simply leaving the location without a target will search all physical and mapped drives.

    &crumb=location:
Murray W
  • 62
  • 4
  • Is there a way to do this with powershell or command line, I have to do this on 500 servers? – Henry Feb 10 '16 at 16:26
  • You didn't mention anything about scripting and 500 servers... That sounds like a full-time job. Coffee break coding might be in order here. Not sure the explorer.exe "search-ms:query=log kind:=folder " command is what you really need but it's a start. – Murray W Feb 10 '16 at 18:55
  • Updated with a simple script. I tested the other methods listed but liked the option to open file location using the old classical Explorer search view. – Murray W Feb 10 '16 at 20:45
  • Down voted? Up voted scripts that just don't seem to work for today's server admin. DOS is nice, it shows files but what good is having a screen filled with lines. The Power Shell scripts didn't work when I tested them. You really need to have a server before you can answer a server question. – Murray W Feb 11 '16 at 15:10