question

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 asked RichMatheisen-8856 commented

execute script on remote server

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-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 answered RichMatheisen-8856 commented

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)")





· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Write-Host writes to the "host" not to the "success" stream. Change Write-Host to Write-Out.

0 Votes 0 ·

The write-host is working/displayed as expected.

it's the invoke i'm worry about.

0 Votes 0 ·

It's not working as expected if you intend its output to be returned from an invoked command.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PowerShelly-7438 avatar image
0 Votes"
PowerShelly-7438 answered RichMatheisen-8856 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

So your real question is how to pass parameters to the script running on the remote machine? You can use the "-ArgumentList" on the Invoke-command.

0 Votes 0 ·