Advertisement
Lee_Dailey

function Get-SpecialFolderInfo - 2018.01.19.18.48.11

Jan 20th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-SpecialFolderInfo
  2.     {
  3.     #region >> CBH [Comment Based Help]
  4.  
  5.     <#
  6.     .Synopsis
  7.         Short description
  8.  
  9.     .DESCRIPTION
  10.         Long description
  11.  
  12.     .EXAMPLE
  13.         Example of how to use this cmdlet
  14.  
  15.     .EXAMPLE
  16.         Another example of how to use this cmdlet
  17.  
  18.     .INPUTS
  19.         Inputs to this cmdlet (if any)
  20.  
  21.     .OUTPUTS
  22.         Output from this cmdlet (if any)
  23.  
  24.     .NOTES
  25.         Version = 2018.01.19.18.48.11
  26.     #>
  27.  
  28.     #endregion >> CBH [Comment Based Help]
  29.  
  30.     #region >> Parameters
  31.     [CmdletBinding ()]
  32.  
  33.     Param
  34.         (
  35.         [Parameter (
  36.             Position = 0)]
  37.             [ValidateNotNullOrEmpty ()]
  38.             [string[]]
  39.             $SpecialFolderName = '*',
  40.  
  41.         [Parameter ()]
  42.             [switch]
  43.             $ReturnOnlyName,
  44.  
  45.         [Parameter ()]
  46.             [switch]
  47.             $ReturnOnlyPath
  48.  
  49.         )
  50.     #endregion >> Parameters
  51.  
  52.     #region >> begin
  53.     begin
  54.         {
  55.         Write-Verbose 'Building list of Special Folder names ...'
  56.         $Full_SFN_List = [enum]::GetNames('System.Environment+SpecialFolder') |
  57.             Sort-Object
  58.         $NoPathFound = '--- No Path Found --'
  59.         }
  60.     #endregion >> begin
  61.  
  62.     #region >> process
  63.     process
  64.         {
  65.         Write-Verbose 'Removing unwanted Special Folder names ...'
  66.         $SFN_WorkingList = $Full_SFN_List -like $SpecialFolderName
  67.         Write-Verbose ('    Found {0} matching items.' -f $SFN_WorkingList.Count)
  68.         foreach ($SWL_Item in $SFN_WorkingList)
  69.             {
  70.             Write-Verbose ('    Processing [ {0} ] ...' -f $SWL_Item)
  71.             $SFPath = [environment]::GetFolderPath($SWL_Item)
  72.             # fill in blank path with $NoPathFound value
  73.             $SFPath = ($NoPathFound, $SFPath)[[bool]$SFPath]
  74.             $TempObject = [PSCustomObject]@{
  75.                 SpecialFolderName = $SWL_Item
  76.                 Path = $SFPath
  77.                 }
  78.  
  79.             if ($ReturnOnlyName -or $ReturnOnlyPath)
  80.                 {
  81.                 switch ($True)
  82.                     {
  83.                     $ReturnOnlyName
  84.                         {
  85.                         $TempObject.SpecialFolderName
  86.                         break
  87.                         }
  88.                     $ReturnOnlyPath
  89.                         {
  90.                         $TempObject.Path
  91.                         break
  92.                         }
  93.                     } # end >> switch ($True)
  94.                 }
  95.                 else
  96.                 {
  97.                 $TempObject
  98.                 } # end >> if ($ReturnOnlyName -or $ReturnOnlyPath)
  99.             } # end >> foreach ($SWL_Item in $SFN_WorkingList)
  100.         } # end >> process
  101.     #endregion >> process
  102.  
  103.     #region >> end
  104.     end
  105.         {
  106.         # nothing here for now
  107.         }
  108.     #endregion >> end
  109.  
  110.     } # end >> function Get-SpecialFolderInfo
  111.  
  112. #region >> testing parameters
  113. Get-SpecialFolderInfo
  114. #Get-SpecialFolderInfo 'mymusic'
  115. #Get-SpecialFolderInfo -SpecialFolderName 'common*' -Verbose
  116. #Get-SpecialFolderInfo -SpecialFolderName 'common*' -ReturnOnlyName
  117. #Get-SpecialFolderInfo -SpecialFolderName 'mydocuments' -ReturnOnlyPath
  118. #endregion >> testing parameters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement