Answered by:
Run Powershell script using PSEXEC

Question
-
Hi,
I need to run powershell script on remote machine using PSEXEC. Basically i need to copy .ps1 to a remote machine and run .ps1 from remote machine ...Can anyone help me..
Thanks
Monday, September 28, 2015 2:38 AM
Answers
-
Do not publish your problem multiple times.
Thanks for undestanding.
Milos
Here is my advice:
se means that offer Powershell for local and remote command executionhttps://technet.microsoft.com/en-us/library/hh849719.aspx
For psexec I prepared script that could copy script to target directory. In my case I used TEMP. You can either share temp or use C$ share, change directory to temp and copy here your script. With one script you can do your job in large number of computers. In execution of psexec do not forget to change firewall setting for file sharing. More details on psexec read this article:
https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
M.
- Proposed as answer by Elaine Jing Wednesday, September 30, 2015 6:59 AM
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Monday, September 28, 2015 6:27 AM -
Hello,
if remoting is enabled you can get to this easier way without 'psexec' in powershell.
try copy-item , more info here and try invoke-command , more info here
sample code in single script, you can add a loop for all servers..
#from share Copy-Item \\share\c$\your.ps1 \\remoteserver\c$\your.ps1 #or local Copy-Item c:\your.ps1 \\remoteserver\c$\your.ps1 #to Run it Invoke-Command -ComputerName remoteHostName -ScriptBlock { powershell -file "c:\your.ps1"}
Regards,
Venu
- Proposed as answer by Elaine Jing Wednesday, September 30, 2015 6:59 AM
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Monday, September 28, 2015 7:16 AM -
This seems to be misunderstanding. Function psexec is for remote execution of scripts that sit on remote computer.
M
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Wednesday, September 30, 2015 12:48 PM
All replies
-
Do not publish your problem multiple times.
Thanks for undestanding.
Milos
Here is my advice:
se means that offer Powershell for local and remote command executionhttps://technet.microsoft.com/en-us/library/hh849719.aspx
For psexec I prepared script that could copy script to target directory. In my case I used TEMP. You can either share temp or use C$ share, change directory to temp and copy here your script. With one script you can do your job in large number of computers. In execution of psexec do not forget to change firewall setting for file sharing. More details on psexec read this article:
https://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
M.
- Proposed as answer by Elaine Jing Wednesday, September 30, 2015 6:59 AM
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Monday, September 28, 2015 6:27 AM -
Hello,
if remoting is enabled you can get to this easier way without 'psexec' in powershell.
try copy-item , more info here and try invoke-command , more info here
sample code in single script, you can add a loop for all servers..
#from share Copy-Item \\share\c$\your.ps1 \\remoteserver\c$\your.ps1 #or local Copy-Item c:\your.ps1 \\remoteserver\c$\your.ps1 #to Run it Invoke-Command -ComputerName remoteHostName -ScriptBlock { powershell -file "c:\your.ps1"}
Regards,
Venu
- Proposed as answer by Elaine Jing Wednesday, September 30, 2015 6:59 AM
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Monday, September 28, 2015 7:16 AM -
Can u pls share ur script which copies to temp using psexecMonday, September 28, 2015 9:32 AM
-
This seems to be misunderstanding. Function psexec is for remote execution of scripts that sit on remote computer.
M
- Marked as answer by Elaine Jing Monday, October 12, 2015 2:25 AM
Wednesday, September 30, 2015 12:48 PM