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

I Need a PSDrive Now!

Posted on September 24, 2021September 24, 2021

I hope you've been enjoying the last few posts on working with PSDrives. To round out the set, I thought I'd remind you of a command in the PSScriptTools module that I use often, especially when teaching a live class or presenting at a conference. As you've seen, I use PSDrives as shortcuts to commonly used folders. Back in my DOS days, I relied on subst.exe. PSDrives are much easier. Here's my typical dilemma and how I solve it.

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!

Since I tend to be in a PowerShell session for demonstrations, I might have a path in my prompt like C:\work\foo\bar\Lab Demo. Ok, this is a bit artificial but you get the point. The path can take up a big chunk of space and is generally irrelevant. To simplify things, I'd like to have a PSDrive rooted to this location. Of course, I'm too lazy to always type out a New-PSDrive command so I wrote a function called New-PSDriveHere that is part of the PSScriptTools module.

The function will create a PSDrive rooted to the specified path. It defaults to your current location. The name of the PSDrive will be the name of the last part of the current path. If this is a multi-word string, the default behavior is to use the last word.

Or I can use the first word.

The function also has a parameter that will automatically change to the new PSDrive once it is created.

And because I want to type the least amount that I can, there are aliases.

By the way, you can override the naming and specify your own.

These PSDrives will only last for the duration of my PowerShell session. But that is fine because I only need them temporarily. If you have similar needs, install PSScripttools from the PowerShell Gallery. New-PSDriveHere works in both Windows PowerShell and PowerShell 7.


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