Skip to main content
freelanceshack.com

Back to all posts

How to Create Disk Shortcut on Desktop Using Powershell?

Published on
5 min read

Table of Contents

Show more
How to Create Disk Shortcut on Desktop Using Powershell? image

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:

$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.

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:

$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:

$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:

$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.