Finding Out a Scripts Parent Folder

If you need to find helper files that are stored in the same folder, you may want to know where a given script is stored. The automatic variable $MyInvocation can provide this information. The following commands tell you the script name and the parent folder name. They only work inside a PowerShell script and you cannot use them interactively.

$MyInvocation.MyCommand.Definition
Split-Path -parent $MyInvocation.MyCommand.Definition

Posted Nov 25 2008, 08:00 AM by ps1

Comments

RichardL wrote re: Finding Out a Scripts Parent Folder
on 02-09-2009 12:56 PM

This did not work for me. I'm using powershell 1.0. What am I doing wrong. There is no output.

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.