# Not able to search string in PS1 files

**URL:** <https://forums.powershell.org/t/not-able-to-search-string-in-ps1-files/8980>\
**Category:** PowerShell Help\
**Created:** [July 9, 2017, 10:55am UTC](https://forums.powershell.org/t/not-able-to-search-string-in-ps1-files/8980 "2017-07-09T10:55:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkata-kalyan](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@venkata-kalyan](https://forums.powershell.org/u/venkata-kalyan)\
**Post date:** [July 9, 2017, 10:55am UTC](https://forums.powershell.org/t/not-able-to-search-string-in-ps1-files/8980/1 "2017-07-09T10:55:22Z")

</div>

Hi,  
Wrote a script which will search through \*.bat & \*.ps1 file and provide the output.

$Results = Foreach ($Server in (get-content “C:\Users\temp\Desktop\Test\Search\_String\Server.txt”))  
{get-childitem \$Server\c$\test\ -recurse -Include \*.bat, \*.ps1 | SELECT-STRING -pattern ‘$4ret&yrt5’ -SimpleMatch | Select @{Name=“Server”;Expression={$Server}},path,Linenumber  
}  
$Results | Select Server,path,Linenumber | Export-Csv C:\Users\temp\Desktop\Test\Search\_String\string\_match\_results.csv -NoType

I am getting output which has string in “.bat” files. But not able to get output for “.PS1” files.  
Can someone help me, where I am doing wrong.

-Kalyan

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [July 9, 2017, 11:32am UTC](https://forums.powershell.org/t/not-able-to-search-string-in-ps1-files/8980/2 "2017-07-09T11:32:46Z")

</div>

Did you confirm that there are \*.ps1 files in the given location? Did you confirm that there are some occurences of the searched pattern in the files? Did you confirm that your Get-ChildItem delivers the output you expect?  
For the future: Please format your code as code and consider to indent your code and try not to use aliasses or abbreviations. This way would it be much easier to read and understand and of course to debug the code.

```
$ServerList = get-content ‘C:\Users\temp\Desktop\Test\Search_String\Server.txt’
$Results = Foreach ($Server in $ServerList){
Get-ChildItem ‘\$Server\c$\test*’ -Recurse -Include *.bat, *.ps1 |
Select-String -Pattern ‘$4ret&yrt5’ -SimpleMatch |
Select-Object @{Name=‘Server’;Expression={$Server}},Path,Linenumber
}
$Results |
Select Server,path,Linenumber |
Export-Csv C:\Users\temp\Desktop\Test\Search_String\string_match_results.csv -NoTypeInformation
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:37pm UTC](https://forums.powershell.org/t/not-able-to-search-string-in-ps1-files/8980/3 "2024-05-16T20:37:56Z")

</div>


