execute script on remote server

PowerShelly 61 Reputation points
2021-07-29T13:41:46.157+00:00

Hope i'm wording it correctly.
LOCALscript.ps1 using System.Windows.Forms.Label and TEXTBOX
LOCALscript.ps1 = gather user's input and execute REMOTEscript.ps1
REMOTEscript.ps1 = process info with users input from LOCALscript.ps1

After successful successfully informations gathered.

Question:
Will my inputs be added to REMOTEscript.ps1?

Example: at the end of LOCALscript1.ps1

invoke-Command -pssession(maybe required) -ComputerName remoteserver01 -filepath \\remoteserver01\d$\REMOTEscript.ps1 -name $objTextBox -address $objTextBox2 -phone $objTextBox3

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. PowerShelly 61 Reputation points
    2021-07-29T14:32:42.157+00:00

    Ok, i was able to test with write host and the parameter works.

    write-host ("REMOTEscript.ps1 -url $($objTextBox2.text), -email $($objTextBox3.text), -type $($objTextBox4.text), -dept $($objTextBox5.text), -san $($objTextBox6.text)")
    

    how do make/convert/transfer it into invoke? Will this work?

    Invoke-Command -ComputerName Remoteserver01 -filepath "\\Remoteserver01\REMOTEscript.ps1 -url $($objTextBox2.text), -email $($objTextBox3.text), -type $($objTextBox4.text), -dept $($objTextBox5.text), -san $($objTextBox6.text)")


  2. Rich Matheisen 47,901 Reputation points
    2021-07-29T14:38:40.653+00:00

    Invoke-Command returns whatever is written to the "success" stream (a.k.a. SDOUT) by the other script or script block. Note that anything the "remote" script writes to any other stream (e.g. ERROR, WARNING, VERBOSE, etc.) will not be returned unless you redirect those streams to the "success" stream.

    See about_redirection or run "help about_redirection" from Powershell.

    0 comments No comments

  3. PowerShelly 61 Reputation points
    2021-07-29T19:35:28.307+00:00

    That's true.

    REMOTEscript.ps1 already written(NOT ME) and functioning.

    Current situation:
    remote in server
    go to directories
    we have to manually run REMOTEscript.ps1 -parameter1 -parameter2 -parameter3 -parameter4

    aiming for LOCALscript.ps1 to do the above from local pc.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.