1

I follow a powershell for penetration testing course and I must use Invoke-command to remotely find words like password, username, credentials in txt file so i make this script called juicyinfo.ps1

Get-ChildItem -Path C:\Users\$env:USERNAME\Desktop\*.txt | Select-String -Pattern password, username, credentials

When I run it with this command:

Invoke-Command -FilePath 'C:\Users\Admin\Desktop\Exercises\Pentester Academy\powershell\juicyinfo.ps1' -ComputerName 192.168.2.32 -Credential adminSMBtest

Or directly with scriptblock:

Invoke-Command -ScriptBlock {Get-ChildItem -Path C:\Users\$env:USERNAME\Desktop\*.txt | Select-String -Pattern password, username, credentials  } -ComputerName 192.168.2.32 -Credential adminSMBtest

But that return blank line like the data is return but with blank lines. I explain more clearly, if I put 50 lines in a txt file with words username, password on the remote computer, I have an output of 50 blank lines for the results of Invoke-Command, if I put 10 lines I have an output of 10 lines...

Locally the script return correct output.

Others scripts like a simple helloworld or Get-process | findstr powershell works perfectly with invoke-command, I tried to ouput to a file and I still have file written with blank line.

  • Like that you're not actually reading the files content. Try to use Get-ChildItem ... | Get-Content | Select-String ... – TobyU Jul 20 '18 at 09:35
  • 1
    That is pure formatting problem. The way formatting is defined for `MatchInfo` objects is not compatible with remoting serialization. All properties are here: `Invoke-Command … | Format-List`. – user4003407 Jul 20 '18 at 09:36
  • @PetSerAl - it's obvious now you mention it but I've been bitten by this just this morning :) – Lieven Keersmaekers Jul 20 '18 at 09:43
  • @PetSerAl you are the man!! thanks for your help, all works fine now. – david kennedy Jul 20 '18 at 09:56

0 Answers0