- 1 year ago
How to create Disk shortcut on desktop using Powershell?
To create a disk shortcut on the desktop using PowerShell, you can use the New-Object
cmdlet to create a Windows Shell Application object and then use the CreateShortcut()
method to create the shortcut. Here's how you can do it:
powershell$diskLetter = "C:" # Replace this with the drive letter you want to create a shortcut for
$shortcutPath = "$env:USERPROFILE\Desktop\$($diskLetter.Substring(0,1))-Drive.lnk"
# Create a Windows Shell Application object
$shell = New-Object -ComObject WScript.Shell
# Create the shortcut
$shortcut = $shell.CreateShortcut($shortcutPath)
$shortcut.TargetPath = $diskLetter
$shortcut.Save()
Write-Host "Shortcut for $diskLetter drive created on the desktop: $shortcutPath"
Save the above PowerShell script in a .ps1 file, and then run it. It will create a shortcut on the desktop with the name "C-Drive.lnk" (or the corresponding drive letter) that points to the specified disk drive.
Replace $diskLetter
with the drive letter you want to create a shortcut for (e.g., "D:", "E:", etc.). The script will create a shortcut with the name "X-Drive.lnk" (where "X" is the drive letter) on the desktop.
You can also customize the $shortcutPath
variable to change the location or name of the shortcut on the desktop. For example, you can change it to "C:\Path\To\Your\Custom\Location\MyShortcut.lnk"
if you want to create the shortcut in a specific folder.
Remember that you might need administrator privileges to create shortcuts on some protected folders, so run the PowerShell script with appropriate permissions if needed.