Code not giving the desired output when running from remote server and providing

Welcome Forums General PowerShell Q&A Code not giving the desired output when running from remote server and providing

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
3 weeks, 5 days ago.

  • Author
    Posts
  • #179367

    Participant
    Topics: 2
    Replies: 0
    Points: 24
    Rank: Member

    I am trying to execute a set of code using "Invoke-Command with computer name and path". It is executing the file but not getting the correct result. When I am executing the same code locally on the server just by using "Run with Powershell" it is giving the correct output. Can anyone please help me with this.

    Example 1) Invoke-Command -ComputerName $ServerName -FilePath "\\$ServerName\C$\textfile.ps1"

    It is giving wrong output

    Example 2) textfile.ps1 —->Run with Powershell

    It is providing correct output

  • #179412

    Senior Moderator
    Topics: 8
    Replies: 1085
    Points: 3,651
    Helping Hand
    Rank: Community Hero

    What is the expected and wrong output here. Is it possible to share both the outputs.
    I suggest not do use script execution from remote path. Try to have it locally or get the script content and convert to scriptblock using [ScriptBlock]::create($content) method.

  • #179469

    Participant
    Topics: 4
    Replies: 76
    Points: 91
    Helping Hand
    Rank: Member

    I might be off here, but it looks like you have the script on the destination server ..and I'm replying from phone.

    of course there might be issues like second hop killing credentials etc.

    Invoke-Command -ComputerName $ServerName -scriptblock {start-process "c:\textfile.ps1"}
    

You must be logged in to reply to this topic.