簡體   English   中英

在具有提升權限的遠程系統上運行Powershell腳本以啟用遠程處理

[英]Run a powershell script on a remote system with elevated permissions to enable remoting

我正在嘗試使用以下代碼將PowerShell腳本復制到遠程Windows 7計算機; 在此計算機上以提升的特權運行它以啟用該系統上的遠程處理。

它將腳本文件復制到遠程系統,但由於$command變量為空,因此未在遠程PowerShell會話中執行$command (以下腳本中的第二行不起作用)。

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

有可能做到這一點嗎? 謝謝,

使用WMI調用CMD來調用PowerShell來調用Start-Process來再次調用PowerShell? 這似乎有點復雜。

嘗試一些簡單得多的方法:

$command = "PowerShell.exe ""C:\Myscript.ps1"" > ""C:\PS-result1.txt"""
Invoke-WmiMethod -class Win32_process -name Create -ArgumentList $command -ComputerName "some-computer"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM