Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Launch a remote powershell process

Reply
 
Old 12-08-2008   #1 (permalink)
Steve Schofield


 
 

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 SERVICEOI)(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 SERVICEOI)(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 SpecsSystem Spec
Old 12-10-2008   #2 (permalink)
Shay Levy [MVP]


 
 

Re: Launch a remote powershell process

Hello Steve,


This is working for me:

$cmd = "powershell -noprofile ""& icacls.exe c:\test /grant 'NT Authority\LOCAL
SERVICEOI)(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 SERVICEOI)(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 SERVICEOI)(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 SERVICEOI)(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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46