/PowerShell/Profile/Modules/Profile/Profile.psm1

https://bitbucket.org/vbsampath/scripts · Powershell · 132 lines · 51 code · 7 blank · 74 comment · 4 complexity · 3ef30fc166b6a861d3098c74a87385f7 MD5 · raw file

  1. <#
  2. .SYNOPSIS
  3. Its a module for all profile related stuff
  4. .DESCRIPTION
  5. Its a module for consolidating all profile related functions
  6. If anything related to a user profile then it goes here
  7. .NOTES
  8. File Name : Profile.psm1
  9. Author : Sampath Vangari - vbsampath@gmail.com
  10. Requires : PowerShell V2 CTP3
  11. Date : 13-June-2014
  12. #>
  13. function Get-UserFavorites
  14. {
  15. <#
  16. .SYNOPSIS
  17. Gets user favorites
  18. .Description
  19. Gets user favorites in windows explorer left top bar with their names and locations for future purposes or just to make a note of it
  20. .Parameter key
  21. key to search for a specific favorite or else print all favorites
  22. .Link
  23. http://powershell.org/wp/forums/topic/find-shortcut-targets/
  24. .Example
  25. # PS> Get-UserFavorites
  26. Description
  27. -----------
  28. Prints all user favorites
  29. .Example
  30. # PS> Get-UserFavorites "Outlook"
  31. Description
  32. -----------
  33. Searches for "Outlook" favorite and then prints it. This is initialization without mentioning parameter name
  34. .Example
  35. # PS> Get-UserFavorites -key "Outlook"
  36. Description
  37. -----------
  38. Searches for "Outlook" favorite and then prints it. With parameter name
  39. #>
  40. [CmdletBinding()]
  41. param(
  42. [Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)][string]$key=""
  43. )
  44. $favorites = Join-Path $env:userprofile "Links"
  45. $Shortcuts = Get-ChildItem -Recurse $favorites -Include *.lnk
  46. $Shell = New-Object -ComObject WScript.Shell
  47. $links=@{}
  48. foreach ($Shortcut in $Shortcuts)
  49. {
  50. $links[$Shortcut.BaseName] = $Shell.CreateShortcut($Shortcut).targetpath
  51. }
  52. [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
  53. if($key -ne "")
  54. {
  55. Write-Output $links.Get_Item($key)
  56. }
  57. else
  58. {
  59. Write-Output $links
  60. }
  61. }
  62. function Get-SpecialFolders
  63. {
  64. <#
  65. .SYNOPSIS
  66. Prints all special folders on the user profile or accessible to user
  67. .Description
  68. Gets all initialized special folders to user
  69. .Parameter key
  70. key to search for a specific special folder or else print all special folders
  71. .Link
  72. http://windowsitpro.com/powershell/easily-finding-special-paths-powershell-scripts
  73. .Example
  74. # PS> Get-SpecialFolders
  75. Description
  76. -----------
  77. Prints all special folders
  78. .Example
  79. # PS> Get-SpecialFolders "Bit Repositories"
  80. Description
  81. -----------
  82. Searches for "Bit Repositories" special folder and then prints it. This is initialization without mentioning parameter name
  83. .Example
  84. # PS> Get-SpecialFolders -key "Bit Repositories"
  85. Description
  86. -----------
  87. Searches for "Bit Repositories" special folder and then prints it. With parameter name
  88. #>
  89. [CmdletBinding()]
  90. param(
  91. [Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)][string]$key=""
  92. )
  93. $SpecialFolders = @{}
  94. $names = [Environment+SpecialFolder]::GetNames([Environment+SpecialFolder])
  95. foreach($name in $names)
  96. {
  97. if($path = [Environment]::GetFolderPath($name)){
  98. $SpecialFolders[$name] = $path
  99. }
  100. }
  101. if($key -ne "")
  102. {
  103. Write-Output $SpecialFolders.Get_Item($key)
  104. }
  105. else
  106. {
  107. Write-Output $SpecialFolders
  108. }
  109. }
  110. Set-Alias guf Get-UserFavorites
  111. Set-Alias gsf Get-SpecialFolders
  112. Export-ModuleMember -function "*"
  113. Export-ModuleMember -Alias "*"