Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Jumping in the PowerShell ISE

Posted on June 6, 2016June 8, 2016

During my day I may be working on multiple files in the PowerShell ISE. Often these files are part of different modules and since I use git I generally need to be in the same directory as the file I'm working on. This necessitates a lot of manually changing location in the PowerShell ISE prompt.  Or I might open the PowerShell ISE and then select some files from MRU list. But again, if I need to jump to the corresponding directory, that can be a tedious process.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

Here's an example.

image

I'm working on my memory tools module and you can see the path. If my ISE prompt is currently C:\ I have to discover the path to the file, which I can do by hovering on the tab, and then use Set-Location or the cd alias to change directories. There needs to be a better way. Here is mine.

The function is quite simple. It gets the filename of the currently active file in the PowerShell ISE and changes the directory location to the script's parent folder. I also save the current location to the location stack with Push-Location.  The benefit is that if you need to jump to a previous location you can use Pop-Location. You'll see that in action in a moment.

Now, you could load this function into your PowerShell ISE profile and add a shortcut to the Add-Ons menu. But I figured since I'm most likely already at the console prompt ready to work to simply create an alias.

Here's an example of what you can expect between selecting different files in the ISE.

image

Notice that you can use the popd alias (for Pop-Location) to jump back to previous locations.

I'm using the function like this in my PowerShell ISE profile.

. C:\scripts\Set-ScriptLocation.ps1

But you are more than welcome to adjust the function as you need. I hope you'll let me know how this works out for you. Use GitHub to report any problems or requests.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d