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.