Search string on remote server

Welcome Forums General PowerShell Q&A Search string on remote server

This topic contains 4 replies, has 3 voices, and was last updated by

js
 
Participant
1 year, 4 months ago.

  • Author
    Posts
  • #74302

    Participant
    Points: 0
    Rank: Member

    Hi,
    I wrote a script which will search string on a remote server. I am facing small issue with this. It is not searching complete folder. It says "Select-String : The file \\servername\c$\abc\stats can not be read: Access to the path
    '\\servername\c$\abc\stats' is denied."

    Script:
    Get-Content .\systems.txt |
    ForEach-Object{
    Select-String -path \\$_\c$\abc\* -pattern test1
    }|
    Select path, pattern, Linenumber |
    Export-Csv C:\Users\kalyan\Desktop\Test\Search_String\string_match_results.csv -NoType

    Can someone help me how to sort this issue?

  • #74303

    Participant
    Points: 0
    Rank: Member

    Found it. I used get-childitem "c:\abc\*" -recurse | SELECT-STRING -pattern 'test1' instead of select-string.

    -Kalyan

    • #74306

      Participant
      Points: 0
      Rank: Member

      Hi,
      I am facing one more issue now. The script is not searching through all files & folder.

      $Results = Foreach ($Server in (get-content "C:\Users\abc\Desktop\Test\Search_String\Server.txt"))

      {get-childitem c:\moon\* -recurse | SELECT-STRING -pattern "$te%$st1" | Select @{Name="Server";Expression={$Server}},path,Linenumber

      }

      $Results | Select Server,path,Linenumber | Export-Csv C:\Users\abc\Desktop\Test\Search_String\string_match_results.csv -NoType

      Can someone help me, what I doing wrong.

      -Kalyan

  • #74311

    Keymaster
    Points: 1,624
    Helping HandTeam Member
    Rank: Community Hero

    You will want to avoid being the first to post a reply to your own post. A lot of us looks for topics with no replies every day, and yours won't appear on that list, which makes it less likely someone will reply to you.

    You should test Get-ChildItem by itself with whatever path you are wanting it to operate against. As written, your command should be working, which means there may be a permissions or other problem. Working with just Get-ChildItem will make it easier to troubleshoot that.

  • #74315
    js

    Participant
    Points: 207
    Helping Hand
    Rank: Participant

    Sometimes you have to use

    get-childitem -force

    to get everything (hidden folders etc).

The topic ‘Search string on remote server’ is closed to new replies.