Run a powershell script on a remote system with elevated permissions to enable remoting -
i trying use following code copy powershell script remote windows 7 machine; run elevated privileges on machine enable remoting on system.
it copying script file remote system not executing command in remote powershell session because of empty $command
variable (the second line in script below not working).
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
is possible accomplish this? thanks,
using wmi call cmd call powershell call start-process call powershell again? seems little complicated.
try simpler:
$command = "powershell.exe ""c:\myscript.ps1"" > ""c:\ps-result1.txt""" invoke-wmimethod -class win32_process -name create -argumentlist $command -computername "some-computer"
Comments
Post a Comment