![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Launch a remote powershell process I'm trying to use powershell to launch a remote powershell instance. It works with cmd.exe, but I run into problems with powershell. It's something with the formating with the ` and continued quotes. I'd like to use powershell all the way around, but cmd.exe seemed to do the job. 'Works $cmd="cmd /c C:\windows\system32\icacls.exe E:\Logs\w3svc1 /grant `"NT Authority\LOCAL SERVICE OI)(CI)(M)`""$server="server123" #$user="domain\userName" #$pass="p@xxxxxx" $process = [WMIClass]"\\$server\ROOT\cimv2:Win32_Process" #$process.psbase.Scope.Options.userName=$user #$process.psbase.Scope.Options.Password=$pass #$process.psbase.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate #$process.psbase.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy $process.Create($cmd) # get process id and returnValue $process.ProcessId $process.ReturnValue 'Doesn't work $cmd="powershell C:\windows\system32\icacls.exe E:\Logs\w3svc1 /grant `"NT Authority\LOCAL SERVICE OI)(CI)(M)`""$server="server123" #$user="domain\userName" #$pass="p@xxxxxx" $process = [WMIClass]"\\$server\ROOT\cimv2:Win32_Process" #$process.psbase.Scope.Options.userName=$user #$process.psbase.Scope.Options.Password=$pass #$process.psbase.Scope.Options.Impersonation = [System.Management.ImpersonationLevel]::Impersonate #$process.psbase.Scope.Options.Authentication = [System.Management.AuthenticationLevel]::PacketPrivacy $process.Create($cmd) # get process id and returnValue $process.ProcessId $process.ReturnValue Steve Schofield |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Launch a remote powershell process Hello Steve, This is working for me: $cmd = "powershell -noprofile ""& icacls.exe c:\test /grant 'NT Authority\LOCAL SERVICE OI)(CI)(M)'"""$process = [WMIClass]"\\$server\ROOT\cimv2:Win32_Process" $process.create($cmd) BTW, you don't have to use powershell to invoke the command on the remote computer. Further more, PowerShell may not be installed on the remote machine, so you can invoke icacls.exe directly. In v2 you can use the Invoke-WmiMethod cmdlet: PS > $cmd = 'icacls.exe c:\test /grant "NT Authority\LOCAL SERVICE OI)(CI)(M)"'PS > Invoke-WmiMethod win32_process -name create -ComputerName $server -ArgumentList $cmd --- Shay Levy Windows PowerShell MVP http://blogs.microsoft.co.il/blogs/ScriptFanatic PowerShell Toolbar: http://tinyurl.com/PSToolbar SS> I'm trying to use powershell to launch a remote powershell instance. SS> It works with cmd.exe, but I run into problems with powershell. SS> It's something with the formating with the ` and continued quotes. SS> I'd like to use powershell all the way around, but cmd.exe seemed to SS> do the job. SS> SS> 'Works SS> SS> $cmd="cmd /c C:\windows\system32\icacls.exe E:\Logs\w3svc1 /grant SS> `"NT Authority\LOCAL SERVICE OI)(CI)(M)`""SS> SS> $server="server123" SS> SS> #$user="domain\userName" SS> SS> #$pass="p@xxxxxx" SS> SS> $process = [WMIClass]"\\$server\ROOT\cimv2:Win32_Process" SS> SS> #$process.psbase.Scope.Options.userName=$user SS> SS> #$process.psbase.Scope.Options.Password=$pass SS> SS> #$process.psbase.Scope.Options.Impersonation = SS> [System.Management.ImpersonationLevel]::Impersonate SS> SS> #$process.psbase.Scope.Options.Authentication = SS> [System.Management.AuthenticationLevel]::PacketPrivacy SS> SS> $process.Create($cmd) SS> SS> # get process id and returnValue SS> SS> $process.ProcessId SS> SS> $process.ReturnValue SS> SS> 'Doesn't work SS> SS> $cmd="powershell C:\windows\system32\icacls.exe E:\Logs\w3svc1 SS> /grant `"NT Authority\LOCAL SERVICE OI)(CI)(M)`""SS> SS> $server="server123" SS> SS> #$user="domain\userName" SS> SS> #$pass="p@xxxxxx" SS> SS> $process = [WMIClass]"\\$server\ROOT\cimv2:Win32_Process" SS> SS> #$process.psbase.Scope.Options.userName=$user SS> SS> #$process.psbase.Scope.Options.Password=$pass SS> SS> #$process.psbase.Scope.Options.Impersonation = SS> [System.Management.ImpersonationLevel]::Impersonate SS> SS> #$process.psbase.Scope.Options.Authentication = SS> [System.Management.AuthenticationLevel]::PacketPrivacy SS> SS> $process.Create($cmd) SS> SS> # get process id and returnValue SS> SS> $process.ProcessId SS> SS> $process.ReturnValue SS> SS> Steve Schofield SS> |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| can i launch a process in the background? | PowerShell | |||
| 32-bit process won't launch on Vista 64 | Software | |||
| Remote process | PowerShell | |||
| Launch Process Explorer @ Startup w/ UAC | Vista General | |||
| Launch Process & return to prompt immediately | PowerShell | |||