0

There is a powershell script located on the C:\. The script executes a .msu file.

Invoke-Command -ComputerName [name] -FilePath C:\file.txt doesn't work because it checks locally on your system for the file to pass over to execute.

I want a powershell script that executes another remote powershell script remotely.

3
  • Possible duplicate of Executing a powershell script locally to run on a remote computer Commented Jun 6, 2017 at 16:04
  • Just google it . Enable the PSRemoting and use Invoke-Command -ComputerName <Computername> -credential <credentials> -FilePath $scriptPath\file.ps1 Commented Jun 6, 2017 at 16:06
  • invoke-command { powershell.exe -noprofile -executionpolicy Bypass c:\myscript.ps1 } -computername box1 Commented Jun 6, 2017 at 16:10

2 Answers 2

0

If you use powershell 5 on both sides you could copy the file via: $TargetSession = New-PSSession -ComputerName server

Copy-Item -ToSession $TargetSession -Path "c:\local\" -Destination "C:\remote\" -Recurse

You could also use copy to admin share c$

Sign up to request clarification or add additional context in comments.

3 Comments

We are using PS v 2. We are trying to mass deploy an update script to 2000+ computers. So the run down is, I created a script to remotely enable winrm on each computer. This will allow us to use the invoke-command remotely. Now, we have a software tool that allows us to push and execute scripts (.bat, .msi, etc). However, it doesn't execute .ps1. So, the .bat script is xcopy two files onto the targets C:\ . This is where this script will come into play.
@schnipdip You are likely going to run into the double hop problem
@BenH I don't believe so. We aren't needing an authentication system. We have direct access to each user account without the need to be authenticated by an authentication server each time. If it does happen I will let you know :)
0

And if you try this method?

Run this command on your local machine :

$computer = "COMP1"    
([WMICLASS]"\\$computer\ROOT\CIMV2:Win32_Process").Create('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -File "script.ps1"')

4 Comments

should this be run locally?
cannot convert \\\ROOT\CIMV2:Win32_Process to type "System.management.managementclass" error: invalid parameter
Is the script stored on the remote machine?
The script is is stored on my computer. Then the microsoft script is stored on the end user root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.