Tuesday, January 31, 2017

Create a file shortcut using PowerShell

Here’s a quick script to create a shortcut to Notepad and put it on the public desktop.

# Create a Shortcut with Windows PowerShell
$TargetFile = "$env:SystemRoot\System32\notepad.exe"
$ShortcutFile = "$env:Public\Desktop\Notepad.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.Save()
Save this script into a PowerShell script file (.ps1 file). Run this script to create notepad shortcut.

No comments: