Search string on remote server error

Hi,
Wrote a script which will loop through multiple server and store the output in a file. But, the script is giving me an error.

Get-Content .\server.txt |
ForEach-Object{
get-childitem “c:\test*” -recurse | SELECT-STRING -pattern “$11t$dpo3”
}|
Select path, pattern, Linenumber |
Export-Csv C:\Users\admin\Desktop\Test\Search_String\string_match_results.csv -NoType

Error:
Select-String : Cannot bind argument to parameter ‘Pattern’ because it is an empty string.
At C:\Users\admin\Desktop\Test\Search_String\Final.ps1:5 char:68

  •     get-childitem "c:\opscripts\*" -recurse | SELECT-STRING -pattern "$11t$dpo3"
    
  •                                                                      ~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:slight_smile: [Select-String], ParameterBindingValidationExceptio
      n
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Powe
      rShell.Commands.SelectStringCommand

Can someone please guide me on this.

-Kalyan

The error message is actually pretty clear. The “pattern” you provide for your Select-String is empty. Why? Because in Powershell variables start with a $ sign. So Powershell “thinks” you want to provide the two variables “$11t” and “$dpo3”. And they are - I assume - empty because you did not declare them, right?

What do you actually mean with “$11t$dpo3”? Should it be taken literal? Then you could enclose it in single quotes and use the parameter -SimpleMatch. If it should be a regular expression I think it does not make sense this way. Because the $ sign represents the end of the line or the end of the string and it does not make sense to have two of them in one short string.

Thanks. -SimpleMatch worked.

-Kalyan