Search string on remote server error


This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Venkata Kalyan Venkata Kalyan 2 weeks, 5 days ago.

  • Author
  • #74498
    Profile photo of Venkata Kalyan
    Venkata Kalyan

    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 |
    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

    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: (:) [Select-String], ParameterBindingValidationExceptio
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Powe

    Can someone please guide me on this.


  • #74501
    Profile photo of Olaf Soyk
    Olaf Soyk

    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.

You must be logged in to reply to this topic.