New ‘Get-FilesContainingText’ function added to SBTools module


SBTools module can be downloaded from the Microsoft Script Center Repository.

To install it, extract the .rar file, and run install-SBTools.ps1 in the folder where you extracted the .rar file.

The Get-FilesContainingText function will search one or more folders and their subfolders for a text pattern and return a list of files containing that pattern.

NAME
Get-FilesContainingText

SYNOPSIS
Function to get a list of iles containg certain text in a given set of
folders and their subfolders

SYNTAX
Get-FilesContainingText [-SearchString] <String> [[-FolderName] <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION
Function returns a list of file names, each containing the search text

PARAMETERS
-SearchString <String>
The text string to search for

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-FolderName <String[]>
Name of the folder(s) to search in.
Function searches in each folder and its subfolders

Required? false
Position? 2
Default value .\
Accept pipeline input? true (ByPropertyName)
Accept wildcard characters? false

-WhatIf [<SwitchParameter>]

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm [<SwitchParameter>]

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

NOTES

Function by Sam Boutros
v1.0 – 08/16/2014

————————– EXAMPLE 1 ————————–

C:\PS>Get-FilesContainingText “import”

This example lists all the files in the current folder and
its subfolders that contain the string “import”

————————– EXAMPLE 2 ————————–

C:\PS>Get-FilesContainingText -SearchString “cheese” -FolderName “d:\Sandbox”,”\\MyServer1\install” -Verbose

This example lists all the files in the folders”d:\Sandbox” and
“\\MyServer1\install” and their subfolders that contain the string “cheese”

RELATED LINKS
https://superwidgets.wordpress.com/category/powershell/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s