Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

PowerShell – Get Special Path

Posted on November 9, 2015 By David Kittell
###############################################################################
## Get-SpecialPath Function (should be an external function in your profile, really)
##   This is an enhancement of [Environment]::GetFolderPath($folder) to add 
##   support for 8 additional folders, including QuickLaunch, and the common 
##   or "All Users" folders... while still supporting My Documents, Startup, etc.
#
FUNCTION Get-SpecialPath 
{
   param([string]$folder)
   BEGIN {
      if ($folder.Length -gt 0) { 
         return $folder | &($MyInvocation.InvocationName); 
      } else {
         $WshShellFolders=@{CommonDesktop=0;CommonStartMenu=1;CommonPrograms=2;CommonStartup=3;PrintHood=6;Fonts=8;NetHood=9};
      }
   }
   PROCESS {
      if($_){
         ## Eliminate the options that are easiest to eliminate
         if($_ -eq "QuickLaunch") {
            $f1 = [Environment]::GetFolderPath("ApplicationData")
            return Join-Path $f1 "\Microsoft\Internet Explorer\Quick Launch"
            ## Test WshShellFolders first because it's easiest won't throw an exception
         } elseif($WshShellFolders.Contains($_)){
            if(-not (Test-Path variable:\global:WshShell)) { $global:WshShell = New-Object -com "WScript.Shell" }
            return (([string[]]$global:WshShell.SpecialFolders) -split " ")[$WshShellFolders[$_]]
         } else {
            ## Finally, try GetFolderPath, and if it throws, change the error message:
            trap
            {
               throw new-object system.componentmodel.invalidenumargumentexception $(
                  "Cannot convert value `"$_`" to type `"SpecialFolder`" due to invalid enumeration values. " +
                  "Specify one of the following enumeration values and try again. The possible enumeration values are: " +
                  "Desktop, Programs, Personal, MyDocuments, Favorites, Startup, Recent, SendTo, StartMenu, MyMusic, " +
                  "DesktopDirectory, MyComputer, Templates, ApplicationData, LocalApplicationData, InternetCache, Cookies, " +
                  "History, CommonApplicationData, System, ProgramFiles, MyPictures, CommonProgramFiles, CommonDesktop, " +
                  "CommonStartMenu, CommonPrograms, CommonStartup, PrintHood, Fonts, NetHood, QuickLaunch")
            }
            return [Environment]::GetFolderPath($_)
         }
      }
   }
}

Get-SpecialPath("quicklaunch")

Reference: http://poshcode.org/5988

All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code PowerShell

Post navigation

Previous post
Next post

Related Posts

PowerShell – Install MySQL

Posted on February 9, 2016

Recently I had to install MySQL and configure it rather quickly, hopefully this will help someone else First off install Chocolatey Then Install MySQL choco install -y mysql All information on this site is shared with the intention to help. Before any source code or program is ran on a…

Read More

Ektron Content Folder Names

Posted on February 4, 2014October 26, 2015

SELECT c.[content_id] ,c.[content_title] ,c.[content_html] ,c.[content_status] ,CASE WHEN c.[content_status] = ‘A’ THEN ‘Approved’ WHEN c.[content_status] = ‘O’ THEN ‘Checked Out’ WHEN c.[content_status] = ‘I’ THEN ‘Checked In’ WHEN c.[content_status] = ‘S’ THEN ‘Submitted for Approval’ WHEN c.[content_status] = ‘M’ THEN ‘Marked for Deletion’ WHEN c.[content_status] = ‘P’ THEN ‘Pending Go Live…

Read More

Update Windows Date/Time

Posted on December 8, 2013February 12, 2016

cls date 11-27-2013 time 5:19:00 PM w32tm /config /syncfromflags:manual /manualpeerlist:"time.windows.com" net stop w32time net start w32time w32tm /resync w32tm /resync pause GitHub: https://gist.github.com/dkittell/c3c930d1b432d51ebb71 Originally Posted on December 8, 2013Last Updated on February 12, 2016 All information on this site is shared with the intention to help. Before any source code…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes