Welcome to MSDN Blogs Sign in | Join | Help

Mount-SpecialFolders.ps1

The other day I showed you how you can use ENUMs.  I showed an example of how you can find all the SPECIALFOLDERs on a system.  Here is a script that I call Mount-SpecialFolders.ps1 which mounts all your special folders as PowerShell drives.

 

# Mount-SpecialFolders.ps1
#
param($Folder="*", [SWITCH]$Verbose, [SWITCH]$PassThru)
foreach ($f in [Enum]::GetValues([System.Environment+SpecialFolder]) |where {$_ -like $Folder}) {
    $drive = New-PSDrive -Name $f -PSProvider FileSystem -Root ([Environment]::GetFolderPath($f)) -Scope Global -ErrorAction SilentlyContinue -Verbose:$verbose
    if ($PassThru)
    {
        Write-Output $drive
    }
}

Enjoy!

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Monday, December 15, 2008 10:04 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Mount-SpecialFolders.ps1

This is a very useful little script. Thank you!

Thursday, December 18, 2008 10:11 AM by Max Schmeling

# re: Mount-SpecialFolders.ps1

Very nice, THX!

Too bad Environment.SpecialFolder enumeration does not contain all special folders.

So I had to do a little extra work - slightly modified the function and run:

$a = New-Object –com Shell.Application

MountFolder "AllUsersDesktop" ($a.namespace(0x19)).Self.Path

MountFolder "AllUsersStartMenu" ($a.namespace(0x16)).Self.Path

...

Btw, hex values can be taken from VBScripts http://www.microsoft.com/technet/scriptcenter/scripts/desktop/special/

Friday, February 20, 2009 5:51 AM by Multidisciplinary

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker