New-PSDrive

PowerShell Cmdlet Spotlight: New-PSDrive

Welcome back to Wahmans Powershell blog! Today we are exploring the New-PSDrive cmdlet, a powerful but sometimes underused part of the PowerShell toolkit.

According to Microsoft’s documentation, New-PSDrive:

Creates temporary and persistent drives that are associated with a location in an item data store.

Think of it like creating a shortcut or symbolic link in PowerShell to quickly access a file system location, registry path, or even a certificate store as though it were a drive. This can be particularly useful when scripting or working with custom providers.

Why New-PSDrive?

By using New-PSDrive, you can simplify your scripts and gain faster access to often-used paths or data providers. Whether it’s navigating application folders or handling configuration data in the registry, this cmdlet has your back.

Examples from Beginner to Advanced

1. Beginner: Create a Temporary Drive for a Local Folder

New-PSDrive -Name MyDocs -PSProvider FileSystem -Root "C:\Users\Public\Documents"
Set-Location MyDocs:

This example maps the “Public Documents” folder as a temporary drive named MyDocs:. It only exists within the current PowerShell session.

2. Intermediate: Mount a Network Share as a Drive

New-PSDrive -Name Shared -PSProvider FileSystem -Root "\\Server\Share" -Persist -Credential (Get-Credential)

This example maps a network share to the drive Shared: and makes it persistent across sessions using the -Persist parameter. A credential prompt ensures secure access.

3. Advanced: Access and Navigate the Registry as a Drive

New-PSDrive -Name MyReg -PSProvider Registry -Root HKEY_LOCAL_MACHINE\SOFTWARE
Set-Location MyReg:

Here, we create a temporary drive pointing to a registry path. This allows you to browse or manipulate registry keys like files and folders—great for system configuration and auditing.

4. Expert: Creating a Drive for the Certificate Store

New-PSDrive -Name CertDrive -PSProvider Certificate -Root Cert:\LocalMachine\My
Set-Location CertDrive:

This example grants you easy access to your machine’s personal certificates, enabling automation around certificate management or validation in enterprise environments.

Final Thoughts

New-PSDrive is more than just a drive creator—it’s a bridge to data sources both familiar and obscure. Start using it to simplify your scripts and enhance your PowerShell Toolbox.

Happy scripting, and I will see you in the next post!

Leave a Reply

Your email address will not be published. Required fields are marked *