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

How to retrieve the script name inside Powershell?

13 views
Skip to first unread message

Ben

unread,
Nov 8, 2009, 8:16:02 AM11/8/09
to

$args contains the passing arguements, but no script name. How to get the
script name inside itself in Powershell?

Thanks!

Marco Shaw [MVP]

unread,
Nov 8, 2009, 8:48:46 AM11/8/09
to
Inside the script, try:
$MyInvocation.InvocationName

"Ben" <B...@discussions.microsoft.com> wrote in message
news:2DF1594D-CDF6-4A43...@microsoft.com...

Martin Zugec

unread,
Nov 8, 2009, 9:05:32 AM11/8/09
to
Hi Ben,

have a look at $MyInvocation variable (ScriptName).

Martin

"Ben" <B...@discussions.microsoft.com> wrote in message
news:2DF1594D-CDF6-4A43...@microsoft.com...
>

RichS [MVP]

unread,
Nov 8, 2009, 9:14:01 AM11/8/09
to

This example shows how to get the name of the running script

1..5 | foreach {"do stuff"}

"Script Name = $($MyInvocation.MyCommand.Name)"
"Script Path = $($MyInvocation.MyCommand.Definition)"


--
Richard Siddaway
All scripts are supplied "as is" and with no warranty
PowerShell MVP
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

01MDM

unread,
Nov 8, 2009, 12:04:10 PM11/8/09
to
$script = $^
$script

01MDM

unread,
Nov 8, 2009, 12:11:33 PM11/8/09
to
On 8 ноя, 20:04, 01MDM <001.dmi...@gmail.com> wrote:
> $script = $^
> $script

The first token of the last entered string. Not a solution. Sorry.

0 new messages