Forum Discussion

jrizzie's avatar
jrizzie
Copper Contributor
Apr 16, 2020
Solved

remote invoke-command (icm) fails when used with Get-ChildItem (gci) and select-string (pattern)

Hello, my goal (simplified) is to find phone-numbers from a remote user. 

I can successfully find matching strings on local machines with the second command, but it does not work when running remotely:

icm -cn <ip-addr> -cr <username> {
gci -path C:\Users\IEUser\Downloads | select-string -Pattern "\d{3}-\d{4}" -AllMatches}

 

I have no error returned, just blank space.

I have successfully ran other remote (icm) commands.

Please let me know if there is a fix to this. 
- Justin

  • jrizzie 

    SOLVED --
    just needed " | fc " before the end of the script-block. better write-up is on stack-overflow.

    icm -cn <ip-addr> -cr <username> {
    gci -path C:\Users\IEUser\Downloads | select-string -Pattern "\d{3}-\d{2}-\d{4}" -AllMatches | fc}

1 Reply

  • jrizzie's avatar
    jrizzie
    Copper Contributor

    jrizzie 

    SOLVED --
    just needed " | fc " before the end of the script-block. better write-up is on stack-overflow.

    icm -cn <ip-addr> -cr <username> {
    gci -path C:\Users\IEUser\Downloads | select-string -Pattern "\d{3}-\d{2}-\d{4}" -AllMatches | fc}

Resources