Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. function Get-Shortcut {
  2. param(
  3. $path = $null
  4. )
  5.  
  6. $obj = New-Object -ComObject WScript.Shell
  7.  
  8. if ($path -eq $null) {
  9. $pathUser = [System.Environment]::GetFolderPath('StartMenu')
  10. $pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')
  11. $path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse
  12. }
  13. if ($path -is [string]) {
  14. $path = dir $path -Filter *.lnk
  15. }
  16. $path | ForEach-Object {
  17. if ($_ -is [string]) {
  18. $_ = dir $_ -Filter *.lnk
  19. }
  20. if ($_) {
  21. $link = $obj.CreateShortcut($_.FullName)
  22.  
  23. $info = @{}
  24. $info.Hotkey = $link.Hotkey
  25. $info.TargetPath = $link.TargetPath
  26. $info.LinkPath = $link.FullName
  27. $info.Arguments = $link.Arguments
  28. $info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}
  29. $info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}
  30. $info.WindowStyle = $link.WindowStyle
  31. $info.IconLocation = $link.IconLocation
  32.  
  33. New-Object PSObject -Property $info
  34. }
  35. }
  36. }
  37.  
  38. function Set-Shortcut {
  39. param(
  40. [Parameter(ValueFromPipelineByPropertyName=$true)]
  41. $LinkPath,
  42. $Hotkey,
  43. $IconLocation,
  44. $Arguments,
  45. $TargetPath
  46. )
  47. begin {
  48. $shell = New-Object -ComObject WScript.Shell
  49. }
  50.  
  51. process {
  52. $link = $shell.CreateShortcut($LinkPath)
  53.  
  54. $PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |
  55. Where-Object { $_.key -ne 'LinkPath' } |
  56. ForEach-Object { $link.$($_.key) = $_.value }
  57. $link.Save()
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement