#PSTip Persistent file system drives

In the previous tip we showed you how  to get the next available drive letter using the Get-AvailableDriveLetter function when we want to create a new mapped network drive.

The Get-AvailableDriveLetter function is one of the commands in the Storage module in Windows 8 and Server 2012.

Starting with PowerShell 3.0, we can now map persistent drives using the enhanced New-PSDrive cmdlet. The following command uses the Get-AvailableDriveLetter function together with the New-PSDrive cmdlet and its -Persist parameter to map a persistent drive:

PS> $letter = Get-AvailableDriveLetter -ReturnFirstLetterOnly
PS> New-PSDrive -Name $letter -PSProvider FileSystem -Root \\Server01\Share -Persist

To disconnect the drive:

PS> Remove-PSDrive -Name $letter

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts