Auch Verknüpfungen oder shortcuts kann man bequem per Powershell erstellen oder auch Löschen.

View source
  1. #------------------------------------------------------------------------------------------
  2.  
  3.  
  4.  
  5. # Name: ShortCuts.ps1
  6. # expected parameters:
  7. # Name = The name of the shortcut
  8. # Target = The path an file the shortcut should point to
  9. # Destination = The location where the shortcut has to be created
  10. # Mode = create | remove
  11. # Argument = Additional argument for the shortcut
  12. # IconLocation = path & file name of file that provides the desired icon.
  13. # IconId = The id of the icon in the IconLocation file
  14. # Usage: .\ShortCuts.ps1 -Name CommandLine -Target c:\windows\System32\cmd.exe -Destinations "$env:PUBLIC\Desktop\,C:\ProgramData\Microsoft\Windows\Start Menu\Programs\" -IconLocation "C:\Windows\System32\shell32.dll" -IconId 24 -Mode create
  15. # Usage: .\ShortCuts.ps1 -Name CommandLine -Target c:\windows\System32\cmd.exe -Destinations "$env:PUBLIC\Desktop\,C:\ProgramData\Microsoft\Windows\Start Menu\Programs\" -IconLocation "C:\Windows\System32\shell32.dll" -IconId 24 -Mode remove
  16. #------------------------------------------------------------------------------------------
  17. param (
  18. [parameter(Mandatory=$true,Position=1)]
  19. [string]$Name,
  20. [parameter(Mandatory=$false)]
  21. [AllowNull()]
  22. [string]$Target,
  23. [parameter(Mandatory=$true)]
  24. [AllowNull()]
  25. [string]$Destinations,
  26. [parameter(Mandatory=$true)]
  27. [string]$Mode,
  28. [parameter(Mandatory=$false)]
  29. [AllowNull()]
  30. [string]$Argument,
  31. [parameter(Mandatory=$false)]
  32. [AllowNull()]
  33. [string]$IconLocation,
  34. [parameter(Mandatory=$false)]
  35. [AllowNull()]
  36. [string]$IconId
  37. )
  38.  
  39.  
  40.  
  41. function create-Shortcut($lnkName,$lnkDestination,$lnkTarget,$lnkArgument,$IconLocation,$IconId)
  42. {
  43. $lnkDestination = $lnkDestination.split(",")
  44.  
  45.  
  46.  
  47. foreach ($dir in $lnkDestination)
  48. {
  49. #create the shortcut object
  50. $WshShell = New-Object -ComObject WScript.Shell
  51. $Shortcut = $WshShell.CreateShortcut("$($dir)$($lnkName).lnk")
  52. #program the shortcut will open
  53. $Shortcut.TargetPath = $lnkTarget
  54. #icon location & Id that the shortcut will use
  55. $Shortcut.IconLocation = "$IconLocation,$IconId"
  56. #any extra parameters that the shortcut may have
  57. $Shortcut.Arguments = "$lnkArgument"
  58. #save the modifications
  59. $Shortcut.Save()
  60. }
  61. }
  62.  
  63.  
  64.  
  65. function remove-Shortcut($lnkName,$lnkDestination)
  66. {
  67. $lnkDestination = $lnkDestination.split(",")
  68.  
  69.  
  70.  
  71. foreach ($dir in $lnkDestination)
  72. {
  73. if (Test-Path "$dir")
  74. {
  75. #remove the shortcut if uninstalled
  76. Remove-Item -Path "$dir$lnkName.lnk"
  77. }
  78. }
  79. }
  80.  
  81.  
  82.  
  83. switch ($Mode)
  84. {
  85. "create"
  86. {
  87. create-Shortcut -lnkName $Name -lnkDestination $Destinations -lnkTarget $Target -lnkArgument $Argument -IconLocation $IconLocation -IconId $IconId
  88. }
  89. "remove"
  90. {
  91. remove-Shortcut -lnkName $Name -lnkDestination $Destinations
  92. }
  93. default{"You did not enter a valid parameter. Mode can be install or uninstall only."}
  94. }
  95.  
  96.  
  97.