SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-1311495%22%20slang%3D%22en-US%22%3Eremote%20invoke-command%20(icm)%20fails%20when%20used%20with%20Get-ChildItem%20(gci)%20and%20select-string%20(pattern)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1311495%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%20my%20goal%20(simplified)%20is%20to%20find%20phone-numbers%20from%20a%20remote%20user.%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3EI%20can%20successfully%20find%20matching%20strings%20on%20local%20machines%20with%20the%20second%20command%2C%20but%20it%20does%20not%20work%20when%20running%20remotely%3A%3C%2FP%3E%3CP%3Eicm%20-cn%20-cr%20%3CUSERNAME%3E%20%7B%3CBR%20%2F%3Egci%20-path%20C%3A%5CUsers%5CIEUser%5CDownloads%20%7C%20select-string%20-Pattern%20%22%5Cd%7B3%7D-%5Cd%7B4%7D%22%20-AllMatches%7D%3C%2FUSERNAME%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20no%20error%20returned%2C%20just%20blank%20space.%3C%2FP%3E%3CP%3EI%20have%20successfully%20ran%20other%20remote%20(icm)%20commands.%3C%2FP%3E%3CP%3EPlease%20let%20me%20know%20if%20there%20is%20a%20fix%20to%20this.%26nbsp%3B%3CBR%20%2F%3E-%20Justin%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1311495%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1311589%22%20slang%3D%22en-US%22%3ERe%3A%20remote%20invoke-command%20(icm)%20fails%20when%20used%20with%20Get-ChildItem%20(gci)%20and%20select-string%20(pattern)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1311589%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623729%22%20target%3D%22_blank%22%3E%40jrizzie%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESOLVED%20--%3CBR%20%2F%3Ejust%20needed%20%22%20%7C%20fc%20%22%20before%20the%20end%20of%20the%20script-block.%20better%20write-up%20is%20on%20stack-overflow.%3C%2FP%3E%3CP%3Eicm%20-cn%20-cr%20%3CUSERNAME%3E%20%7B%3CBR%20%2F%3Egci%20-path%20C%3A%5CUsers%5CIEUser%5CDownloads%20%7C%20select-string%20-Pattern%20%22%5Cd%7B3%7D-%5Cd%7B2%7D-%5Cd%7B4%7D%22%20-AllMatches%20%7C%20fc%7D%3C%2FUSERNAME%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
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)
Solution

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