December 15th, 2008

Mount-SpecialFolders.ps1

PowerShell Team
PowerShell Team

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

Author

PowerShell Team
PowerShell Team

PowerShell is a task-based command-line shell and scripting language built on .NET. PowerShell helps system administrators and power-users rapidly automate tasks that manage operating systems (Linux, macOS, and Windows) and processes.

0 comments

Discussion are closed.