PowerShell: Search multiple files for text string

My client had an issue where a script built years ago, deployed by SCCM, had changed the registry settings of IE on some computers.  However, the registry setting was causing new problems and the script needed to be removed from deployment.  The client didn't know which script was causing the issue, so I used this PowerShell script to scan the SMSPKGD$ folder in search of the registry key in the files.

$Extensions = @("bat","cmd","vbs","ps1")

$FoundText = @()

ForEach ($Ext in $Extensions) {

$Text = Select-String \\ServerName\SMSPKGD$\*\*.$Ext -Pattern "Text you are looking for"

$FoundText += $Text }

If ($FoundText) {$FoundText | Out-GridView}

Within a minute I had found the script that was changing the registry and disabled the advertisement.

Comments (2)

  1. Ryan Webb says:

    Just one correction, in the statement ForEach ($Ext in Extensions) { , you are missing the $ before Extensions, it should instead read ForEach ($Ext in $Extensions) {

    1. Ryan.Catlin says:

      Thanks for the catch Ryan Webb.

Skip to main content