Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

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

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 09-12-2006   #1 (permalink)
Brandon Shell
Guest


 

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]
Guest


 

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]
Guest


 

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?=
Guest


 

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
Guest


 

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]
Guest


 

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]
Guest


 

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
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a folder on a remote machine? Gerry Hickman PowerShell 16 03-18-2008 04:53 PM
checked for logged on user on remote machine + remote reboot Ben Christian PowerShell 2 03-10-2008 06:52 PM
execute command on remote system Justin Rich PowerShell 3 11-30-2007 08:40 AM
getting remote machine directory IT Staff PowerShell 3 07-19-2007 04:11 AM
remote desktop howto vista Vista networking & sharing 4 12-11-2006 03:01 PM


Update your Vista Drivers Update Your Drivers Now!!

Vistax64.com 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 2005-2008