Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Wait for invoke-expression completion

2,267 views
Skip to first unread message

Doug

unread,
Apr 30, 2007, 3:09:57 PM4/30/07
to
After an invoke-expression statement, how can you make the script wait for it to complete?
My workaround for this is to the start-sleep cmdlet, with a safe time interval to ensure completion.
Is there a simple, more straightforward way?
- Doug


Gerd Schneider

unread,
May 1, 2007, 1:54:01 PM5/1/07
to
As far as I understand the situation there is only one scenario where
invoke-expression does not wait and this is when you launch an external
non-console application.

I don't know of a PS internal solution for this problem, but you may try
these workarounds:

1) The PSCX (http://www.codeplex.com/PowerShellCX) contain a CmdLet
"start-process" which can do the job

2) Utilize the Scripting Host:
$shell = new-object -com wscript.shell
$shell.run('calc', $null, $true)

3) Use the System.Diagnostics.Process class

I personally ended up with #2.

Gerd

RichS

unread,
May 2, 2007, 11:07:02 AM5/2/07
to
You may want to have a look at this article on the subject

http://blogs.technet.com/industry_insiders/pages/executing-a-command-line-utility-from-powershell-and-waiting-for-it-to-finish.aspx
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

Doug

unread,
May 12, 2007, 4:48:59 PM5/12/07
to
Thank you Rich and Gerd,

The .NET System.Diagnostics class approach is very informative.
This is important stuff to know to get the power out of PowerShell.

- Doug

"RichS" <Ri...@discussions.microsoft.com> wrote in message
news:0DB496B8-E801-444D...@microsoft.com...

0 new messages