【发布时间】:2016-02-08 02:39:18
【问题描述】:
我正在尝试使用以下代码将 PowerShell 脚本复制到远程 Windows 7 机器;在这台机器上以提升的权限运行它以在该系统上启用远程处理。
它正在将脚本文件复制到远程系统,但由于 $command 变量为空(下面脚本中的第二行不起作用),它没有在远程 PowerShell 会话中执行命令。
Copy-Item -Path C:\users\user1\Myscript.ps1 -Destination \\some-computer\c$\Myscript.ps1
$command = PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\Myscript.ps1""' -Verb RunAs > C:\PS-result1.txt}"
$cmd = "CMD.EXE /c "+$command
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $cmd -ComputerName "some-computer"
Start-Sleep -s 8
Get-Content \\some-computer\C$\PS-result1.txt
有可能做到这一点吗? 谢谢,
【问题讨论】:
标签: powershell