[英]Executing a powershell script on a remote computer file system
There is a powershell script located on the C:\\
. 在
C:\\
上有一个powershell脚本。 The script executes a .msu file. 该脚本执行一个.msu文件。
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. Invoke-Command -ComputerName [name] -FilePath C:\\file.txt
不起作用,因为它在系统上本地检查要传递的文件以执行。
I want a powershell script that executes another remote powershell script remotely. 我想要一个Powershell脚本,该脚本可以远程执行另一个远程Powershell脚本。
If you use powershell 5 on both sides you could copy the file via: $TargetSession = New-PSSession -ComputerName server 如果在两侧都使用Powershell 5,则可以通过以下方式复制文件:$ TargetSession = New-PSSession -ComputerName服务器
Copy-Item -ToSession $TargetSession -Path "c:\\local\\" -Destination "C:\\remote\\" -Recurse 复制项-ToSession $ TargetSession-路径“ c:\\ local \\”-目标“ C:\\ remote \\”-递归
You could also use copy to admin share c$ 您也可以使用复制来管理共享c $
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"')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.