How to Create Disk Shortcut on Desktop Using Powershell?

8 minutes read

To create a disk shortcut on the desktop using PowerShell, you can use the New-Object cmdlet to create a shortcut and then use the CreateShortcut method to specify the target location of the disk.


First, open PowerShell as an administrator. Then use the following commands:

1
2
3
4
$WshShell = New-Object -ComObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Disk.lnk")
$Shortcut.TargetPath = "D:\"
$Shortcut.Save()


In this script, the $Shortcut.TargetPath specifies the location of the disk you want to create a shortcut for. Change the "D:" to the appropriate drive letter that you want to create the shortcut for.


After running the script, you should see a shortcut named "Disk" on your desktop that links to the specified disk drive.

Best PowerShell Books to Read of December 2024

1
Mastering PowerShell Scripting: Automate and manage your environment using PowerShell 7.1, 4th Edition

Rating is 5 out of 5

Mastering PowerShell Scripting: Automate and manage your environment using PowerShell 7.1, 4th Edition

2
PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

Rating is 4.9 out of 5

PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

3
Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS

Rating is 4.8 out of 5

Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS

4
PowerShell for Sysadmins: Workflow Automation Made Easy

Rating is 4.7 out of 5

PowerShell for Sysadmins: Workflow Automation Made Easy

5
PowerShell for Beginners: Learn PowerShell 7 Through Hands-On Mini Games

Rating is 4.6 out of 5

PowerShell for Beginners: Learn PowerShell 7 Through Hands-On Mini Games

6
Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

Rating is 4.5 out of 5

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

7
PowerShell Pocket Reference: Portable Help for PowerShell Scripters

Rating is 4.4 out of 5

PowerShell Pocket Reference: Portable Help for PowerShell Scripters


What is the step-by-step guide to create a disk shortcut on the desktop using PowerShell?

  1. Open PowerShell by searching for it in the Start menu or by pressing Windows Key + X and selecting Windows PowerShell.
  2. In PowerShell, type the following command to create a new shortcut on the desktop: New-Object -ComObject WScript.Shell).CreateShortcut("$home\Desktop\Drive C.lnk").TargetPath = "C:"
  3. Replace "Drive C" with the name you want to give to the shortcut and "C:" with the path of the disk you want to create the shortcut for.
  4. Press Enter to execute the command. This will create a shortcut named "Drive C" on your desktop that links to the C: drive.
  5. You can then find the new shortcut on your desktop and double-click it to open the C: drive in File Explorer.


Note: Make sure to run PowerShell as an administrator to create shortcuts on the desktop.


What is the process to create a disk shortcut on the desktop using PowerShell without errors?

To create a disk shortcut on the desktop using PowerShell without errors, you can follow these steps:

  1. Open PowerShell as an administrator.
  2. Use the following command to create a shortcut to a disk on the desktop:
1
2
3
4
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Disk.lnk")
$Shortcut.TargetPath = "YourDiskPath"
$Shortcut.Save()


Replace "YourDiskPath" with the path of the disk you want to create a shortcut for. Make sure to include the drive letter and any folders if necessary.

  1. Run the command in PowerShell to create the shortcut. This should create a shortcut named "Disk" on your desktop that points to the specified disk.
  2. Check your desktop to ensure that the shortcut was created successfully without any errors.


Following these steps should help you create a disk shortcut on the desktop using PowerShell without encountering any errors.


What is the PowerShell code to add a disk shortcut on the desktop?

Here is an example of PowerShell code that adds a shortcut for a disk on the desktop:

1
2
3
4
5
6
7
$outFile = "$env:USERPROFILE\Desktop\DiskShortcut.lnk"
$cimObj = Get-CimInstance -Query "SELECT * FROM Win32_LogicalDisk WHERE DriveType = 3"
$wscript = New-Object -ComObject WScript.Shell
$shortcut = $wscript.CreateShortcut($outFile)

$shortcut.TargetPath = $cimObj.DeviceID
$shortcut.Save()


This code will create a shortcut for the disk on the desktop. The disk is specified using the Get-CimInstance cmdlet, which retrieves information about the logical disks on the system. The WScript.Shell COM object is used to create the shortcut, and the CreateShortcut method is used to set the target path for the shortcut. Finally, the Save method is called to save the shortcut to the specified path on the desktop.


How to implement a desktop shortcut for a disk drive with PowerShell?

To create a desktop shortcut for a disk drive using PowerShell, you can use the following script:

  1. First, open PowerShell by searching for it in the Start menu and running it as an administrator.
  2. Use the following script to create a shortcut to a disk drive on the desktop:
1
2
3
4
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$home\desktop\DiskDrive.lnk")
$Shortcut.TargetPath = "D:\"
$Shortcut.Save()


  1. Replace "D:\" with the path to the disk drive you want to create a shortcut for.
  2. Run the script in PowerShell. This will create a shortcut named "DiskDrive" on your desktop that links to the specified disk drive.
  3. You can double-click on the shortcut to open the disk drive in File Explorer.


Note: Make sure to modify the script with the correct drive path before running it.


How to use PowerShell to add a disk shortcut on the desktop?

To add a disk shortcut on the desktop using PowerShell, you can follow these steps:

  1. Open PowerShell as an administrator by searching for "PowerShell" in the Start menu, right-clicking on it, and selecting "Run as administrator".
  2. Use the following command to create a shortcut on the desktop to a specific disk: $WshShell = New-Object -ComObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$env:USERPROFILE\Desktop\Disk.lnk") $Shortcut.TargetPath = "D:\" $Shortcut.Save()
  3. Replace "D:\" with the drive letter of the disk you want to create a shortcut for.
  4. Run the script by pressing Enter. This will create a shortcut named "Disk.lnk" on your desktop that points to the specified disk.
  5. You can now double-click on the shortcut to open the disk in File Explorer.


Note: Make sure to run the PowerShell script as an administrator to avoid any permissions issues.

Twitter LinkedIn Telegram Whatsapp

Related Posts:

To create a shortcut using PowerShell, you can follow these steps:Open PowerShell: Launch PowerShell by searching for it in the Start menu or by pressing Windows + X and selecting "Windows PowerShell" or "Windows PowerShell (Admin)." Create the...
To add a path to a PowerShell object in C#, you can use the AddScript method provided by the System.Management.Automation.Runspaces.Runspace class. This method allows you to add a script or command to the PowerShell object.Here is an example code snippet: usin...
To find the CPU and RAM usage using PowerShell, you can utilize various commands and methods. Here is how you can do it:Open PowerShell by pressing the Windows key, typing "PowerShell," and selecting "Windows PowerShell" or "PowerShell"...