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 - How to execute external program from powershell

Reply
 
Old 05-16-2009   #1 (permalink)
Danny Ni


 
 

How to execute external program from powershell

Hi,

Can someone show me how to execute an external program using powershell
script? say:

$strFolderSource = "\\devserver1\downloads"
$strFolderTarget = "\\devserver1\downloads"
$strCmd = "robocopy /S " + $strFolderSource + " " + $strFolderTarget

I need to execute $strCmd.

TIA



My System SpecsSystem Spec
Old 05-17-2009   #2 (permalink)
tojo2000


 
 

Re: How to execute external program from powershell

On May 16, 8:50*pm, "Danny Ni" <d...@xxxxxx> wrote:
Quote:

> Hi,
>
> Can someone show me how to execute an external program using powershell
> script? say:
>
> $strFolderSource = "\\devserver1\downloads"
> $strFolderTarget = "\\devserver1\downloads"
> $strCmd = "robocopy /S " + $strFolderSource + " " + *$strFolderTarget
>
> I need to execute $strCmd.
>
> TIA
Try this:

[system.diagnostics.process]::start($strCmd)

or if you're using v2, use the Start-Process cmdlet.

Here's the MSDN article on the method:
http://msdn.microsoft.com/en-us/libr...ess.start.aspx
My System SpecsSystem Spec
Old 05-17-2009   #3 (permalink)
Vadims Podans [MVP]


 
 

Re: How to execute external program from powershell

mm..looks like you need this:

Invoke-Expression $strCMD
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv

"Danny Ni" <dndn@xxxxxx> rakstija zinojuma
"news:OMNNpKq1JHA.480@xxxxxx"...
Quote:

> Hi,
>
> Can someone show me how to execute an external program using powershell
> script? say:
>
> $strFolderSource = "\\devserver1\downloads"
> $strFolderTarget = "\\devserver1\downloads"
> $strCmd = "robocopy /S " + $strFolderSource + " " + $strFolderTarget
>
> I need to execute $strCmd.
>
> TIA
>
My System SpecsSystem Spec
Old 05-17-2009   #4 (permalink)
Shay Levy [MVP]


 
 

Re: How to execute external program from powershell

Hi Danny,

You can also try with the call operator (i.e "&"):

& robocopy /S $strFolderSource $strFolderTarget



---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar



DN> Hi,
DN>
DN> Can someone show me how to execute an external program using
DN> powershell script? say:
DN>
DN> $strFolderSource = "\\devserver1\downloads"
DN> $strFolderTarget = "\\devserver1\downloads"
DN> $strCmd = "robocopy /S " + $strFolderSource + " " +
DN> $strFolderTarget
DN> I need to execute $strCmd.
DN>
DN> TIA
DN>


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Can only execute gpg from powershell under MY account PowerShell
How to execute a webtest from Powershell PowerShell
Powershell Execute process PowerShell
passing parameters to an external program using PowerShell variables PowerShell
How to execute (perl) scripts in Powershell without DOS box 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