Monday, 14 February 2011

New-Shortcut.ps1

  1. <# 
  2. .SYNOPSIS 
  3.    This script creates a shortcut to Notepad on the Desktop 
  4. .DESCRIPTION 
  5.    This script creates a Wscript.shell item, then creates  
  6.    a shortcut on the desktop to Notepad.exe. 
  7. .NOTES 
  8.     File Name  : New-Shortcut.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell Version 2.0 
  11. .LINKS 
  12.     This post is a re-implementation of an MSDN Script 
  13.         http://msdn.microsoft.com/en-us/library/0ea7b5xe%28VS.85%29.aspx 
  14.     Posted to Powershell Scripts Blog 
  15.         HTTP://Pshscripts.blogspot.com 
  16. .EXAMPLE 
  17.    Left as an exercise for the reader 
  18. #> 
  19.  
  20. # create wscript object 
  21. $WshShell = New-Object -com Wscript.Shell 
  22.  
  23. #Get Desktop location 
  24. $Desktop  = $WshShell.SpecialFolders.item("Desktop"
  25.  
  26. # create a new shortcut 
  27. $ShellLink                  = $WshShell.CreateShortcut($Desktop + "\Shortcut Script.lnk"
  28. $ShellLink.TargetPath       = $WScript.ScriptFullName 
  29. $ShellLink.WindowStyle      = 1 
  30. $ShellLink.Hotkey           = "CTRL+SHIFT+F" 
  31. $ShellLink.IconLocation     = "notepad.exe, 0" 
  32. $ShellLink.Description      = "Shortcut Script" 
  33. $ShellLink.WorkingDirectory = $Desktop 
  34.  
  35. #Save the link to the desktop 
  36. $ShellLink.Save()