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

New Contributor

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

1 Reply
best response confirmed by jrizzie (New Contributor)


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}