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 - HowTo: Run a Command (.exe or .cmd) on a Remote Machine

Reply
 
Old 09-12-2006   #1 (permalink)
Brandon Shell


 
 

HowTo: Run a Command (.exe or .cmd) on a Remote Machine

I appologize if this has been asked before, but I couldnt find any
reference.

Goal:
-----
Basically I just want to run an App that resides in C:\windows\system32 of
the remote machine. I normally just use psexec \\server App.exe
Is there a more powershellish way to do this?



My System SpecsSystem Spec
Old 09-12-2006   #2 (permalink)
Narayanan Lakshmanan [MSFT]


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

The PowerShellish way will be available in a future version of PowerShell
which will including remoting features. Stay tuned.

--
Narayanan Lakshmanan [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:%235RDwBq1GHA.772@TK2MSFTNGP05.phx.gbl...
>I appologize if this has been asked before, but I couldnt find any
>reference.
>
> Goal:
> -----
> Basically I just want to run an App that resides in C:\windows\system32 of
> the remote machine. I normally just use psexec \\server App.exe
> Is there a more powershellish way to do this?
>


My System SpecsSystem Spec
Old 09-13-2006   #3 (permalink)
Thomas Lee [MVP]


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

Brandon Shell wrote:
> I appologize if this has been asked before, but I couldnt find any
> reference.
>
> Goal:
> -----
> Basically I just want to run an App that resides in C:\windows\system32 of
> the remote machine. I normally just use psexec \\server App.exe
> Is there a more powershellish way to do this?


Take a look at the ps tools from winternals - these may help

--
Thomas Lee
DoctorDns@gmail.com
My System SpecsSystem Spec
Old 09-13-2006   #4 (permalink)
=?Utf-8?B?L1wvXG9cL1wvIFtNVlBd?=


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

You can use WMI

MowPS>(new-object
management.ManagementClass('\\computer\root\cimv2:win32_process')).InvokeMethod('Create','calc.exe'
)
0

Note that calc is just an test example, it is not interactive lanched remove

Sample Script :
http://mow001.blogspot.com/2006/03/m...on-update.html

# win32_process Create-Method Sample Script
# Created by Get-WmiMethodHelp (v3)
# /\/\o\/\/ 2006
# Fill InParams values before Executing
# InParams that are Remarked (#) are Optional


$Class = "win32_process"
$Method = "Create"
$MP = new-object system.management.ManagementPath
$MP.Server = "."
$MP.NamespacePath = "root\cimv2"
$MP.ClassName = $Class


$MC = new-object system.management.ManagementClass($MP)
$InParams = $mc.GetMethodParameters($Method)


$InParams["CommandLine"] = [string]
$InParams["CurrentDirectory"] = [string]
$InParams["ProcessStartupInformation"] = [object:Win32_ProcessStartup]


"Calling win32_process : Create with Parameters :"
$inparams.get_properties() | select name,Value


$R = $mc.InvokeMethod($Method, $inParams, $Null)
"Result : "
$R


"Thomas Lee [MVP]" wrote:

> Brandon Shell wrote:
> > I appologize if this has been asked before, but I couldnt find any
> > reference.
> >
> > Goal:
> > -----
> > Basically I just want to run an App that resides in C:\windows\system32 of
> > the remote machine. I normally just use psexec \\server App.exe
> > Is there a more powershellish way to do this?

>
> Take a look at the ps tools from winternals - these may help
>
> --
> Thomas Lee
> DoctorDns@gmail.com
>

My System SpecsSystem Spec
Old 09-13-2006   #5 (permalink)
Brandon Shell


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

What kind of return should I expect? Does it just start the app and hope for
the best or does it wait for the app to close?


"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:9EA2014C-9C96-4950-A2C6-67020CE0416B@microsoft.com...
> You can use WMI
>
> MowPS>(new-object
> management.ManagementClass('\\computer\root\cimv2:win32_process')).InvokeMethod('Create','calc.exe'
> )
> 0
>
> Note that calc is just an test example, it is not interactive lanched
> remove
>
> Sample Script :
> http://mow001.blogspot.com/2006/03/m...on-update.html
>
> # win32_process Create-Method Sample Script
> # Created by Get-WmiMethodHelp (v3)
> # /\/\o\/\/ 2006
> # Fill InParams values before Executing
> # InParams that are Remarked (#) are Optional
>
>
> $Class = "win32_process"
> $Method = "Create"
> $MP = new-object system.management.ManagementPath
> $MP.Server = "."
> $MP.NamespacePath = "root\cimv2"
> $MP.ClassName = $Class
>
>
> $MC = new-object system.management.ManagementClass($MP)
> $InParams = $mc.GetMethodParameters($Method)
>
>
> $InParams["CommandLine"] = [string]
> $InParams["CurrentDirectory"] = [string]
> $InParams["ProcessStartupInformation"] = [object:Win32_ProcessStartup]
>
>
> "Calling win32_process : Create with Parameters :"
> $inparams.get_properties() | select name,Value
>
>
> $R = $mc.InvokeMethod($Method, $inParams, $Null)
> "Result : "
> $R
>
>
> "Thomas Lee [MVP]" wrote:
>
>> Brandon Shell wrote:
>> > I appologize if this has been asked before, but I couldnt find any
>> > reference.
>> >
>> > Goal:
>> > -----
>> > Basically I just want to run an App that resides in C:\windows\system32
>> > of
>> > the remote machine. I normally just use psexec \\server App.exe
>> > Is there a more powershellish way to do this?

>>
>> Take a look at the ps tools from winternals - these may help
>>
>> --
>> Thomas Lee
>> DoctorDns@gmail.com
>>



My System SpecsSystem Spec
Old 09-13-2006   #6 (permalink)
Alex K. Angelopoulos [MVP]


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

The meaning of the return values is documented in MSDN:
http://msdn.microsoft.com/library/en...32_process.asp

The naming convention is a bit strange for methods of classes , but you can
find the base documentation for any WMI class by using a URL of the form
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/<WMI-Class-Name>.asp
This always has breakouts for the methods such as Create at the bottom.


"Brandon Shell" <tshell.mask@gmail.com> wrote in message
news:%23UaFUyy1GHA.4908@TK2MSFTNGP02.phx.gbl...
> What kind of return should I expect? Does it just start the app and hope
> for the best or does it wait for the app to close?
>
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:9EA2014C-9C96-4950-A2C6-67020CE0416B@microsoft.com...
>> You can use WMI
>>
>> MowPS>(new-object
>> management.ManagementClass('\\computer\root\cimv2:win32_process')).InvokeMethod('Create','calc.exe'
>> )
>> 0
>>
>> Note that calc is just an test example, it is not interactive lanched
>> remove
>>
>> Sample Script :
>> http://mow001.blogspot.com/2006/03/m...on-update.html
>>
>> # win32_process Create-Method Sample Script
>> # Created by Get-WmiMethodHelp (v3)
>> # /\/\o\/\/ 2006
>> # Fill InParams values before Executing
>> # InParams that are Remarked (#) are Optional
>>
>>
>> $Class = "win32_process"
>> $Method = "Create"
>> $MP = new-object system.management.ManagementPath
>> $MP.Server = "."
>> $MP.NamespacePath = "root\cimv2"
>> $MP.ClassName = $Class
>>
>>
>> $MC = new-object system.management.ManagementClass($MP)
>> $InParams = $mc.GetMethodParameters($Method)
>>
>>
>> $InParams["CommandLine"] = [string]
>> $InParams["CurrentDirectory"] = [string]
>> $InParams["ProcessStartupInformation"] = [object:Win32_ProcessStartup]
>>
>>
>> "Calling win32_process : Create with Parameters :"
>> $inparams.get_properties() | select name,Value
>>
>>
>> $R = $mc.InvokeMethod($Method, $inParams, $Null)
>> "Result : "
>> $R
>>
>>
>> "Thomas Lee [MVP]" wrote:
>>
>>> Brandon Shell wrote:
>>> > I appologize if this has been asked before, but I couldnt find any
>>> > reference.
>>> >
>>> > Goal:
>>> > -----
>>> > Basically I just want to run an App that resides in
>>> > C:\windows\system32 of
>>> > the remote machine. I normally just use psexec \\server App.exe
>>> > Is there a more powershellish way to do this?
>>>
>>> Take a look at the ps tools from winternals - these may help
>>>
>>> --
>>> Thomas Lee
>>> DoctorDns@gmail.com
>>>

>
>



My System SpecsSystem Spec
Old 09-18-2006   #7 (permalink)
Thomas Lee [MVP]


 
 

Re: HowTo: Run a Command (.exe or .cmd) on a Remote Machine

//o// [MVP] wrote:
> You can use WMI
>
> MowPS>(new-object
> management.ManagementClass('\\computer\root\cimv2:win32_process')).InvokeMethod('Create','calc.exe'
> )
> 0
>
> Note that calc is just an test example, it is not interactive lanched remove
>
> Sample Script :
> http://mow001.blogspot.com/2006/03/m...on-update.html
>
> # win32_process Create-Method Sample Script
> # Created by Get-WmiMethodHelp (v3)
> # /\/\o\/\/ 2006
> # Fill InParams values before Executing
> # InParams that are Remarked (#) are Optional
>
>
> $Class = "win32_process"
> $Method = "Create"
> $MP = new-object system.management.ManagementPath
> $MP.Server = "."
> $MP.NamespacePath = "root\cimv2"
> $MP.ClassName = $Class
>
>
> $MC = new-object system.management.ManagementClass($MP)
> $InParams = $mc.GetMethodParameters($Method)
>
>
> $InParams["CommandLine"] = [string]
> $InParams["CurrentDirectory"] = [string]
> $InParams["ProcessStartupInformation"] = [object:Win32_ProcessStartup]
>
>
> "Calling win32_process : Create with Parameters :"
> $inparams.get_properties() | select name,Value
>
>
> $R = $mc.InvokeMethod($Method, $inParams, $Null)
> "Result : "
> $R


What about credentials??
;-)

Thomas
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to get the output of a command executed on a remote machine? PowerShell
is there anyway to set on a remote machine "Log On As A Service" withthe SC sdset or other SC command .NET General
How to view remote certificates installed on remote machine? PowerShell
checked for logged on user on remote machine + remote reboot PowerShell
remote desktop howto Vista networking & sharing


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