- 1 year ago
Powershell create shortcut with Drive as variable
Comment
1 / 1
To create a shortcut with a drive as a variable in PowerShell, you can use the New-Item
cmdlet with the -ItemType
parameter set to "SymbolicLink"
to create the shortcut, and the -Target
parameter to specify the target file or folder.
Here's an example script that creates a shortcut to a folder on a specified drive:
powershell$drive = "D:"
$target = "D:\Documents\MyFolder"
$shortcutPath = "C:\Users\Username\Desktop\MyShortcut.lnk"
New-Item -ItemType "SymbolicLink" -Path $shortcutPath -Target $target
In this example, the script creates a shortcut named MyShortcut.lnk
on the desktop of the current user that points to the folder D:\Documents\MyFolder
. The drive letter is stored in the $drive
variable, which can be easily modified to point to a different drive.