I hope above article helps you to understand how to create a shortcut in PowerShell for application, file or folder. You can use use CTRL SHIFT T to open the folder.Ĭool Tip: Best way to download zip file using PowerShell! Conclusion Upon invoking Save() method, it create a shortcut on user desktop for folder. We have added TargetPath, WindowsStyle and HotKey to shortcut variable. Later, we create an object of WScript and assign it to variable. In the above PowerShell script, first we define location and path for shortcut folder. $ShortcutPath = "C:\Users\admin\Desktop\powershell.lnk" Let’s consider, we have to create a shortcut to folder available on D:\ drive and save shortcut on user desktop.Ĭopy below PowerShell script and run it on your computer to create shortcut with PowerShell. In this example, I will explain you how to create shortcut to folder on user desktop or on remote computer with PowerShell. $shortcut = $WscriptObj.CreateShortcut($ShortcutPath)Ĭool Tip: Do you know how to get free disk space using PowerShell! PowerShell Create shortcut to Folder $WScriptObj = New-Object -ComObject ("WScript.Shell") $ShortcutPath = "C:\Users\Gary.Thomas\Desktop\MsEdge.lnk" Step #7: PowerShell Create Shortcut Code $SourceFilePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" lnk $ShortcutPath = "C:\Users\Gary.Thomas\Desktop\MsEdge.lnk" Step 3: Create new WScript.Shell object and assign it to variable $WScriptObj = New-Object -ComObject ("WScript.Shell") Step #4: Create Shortcut using shortcut path specified in Step 2 $shortcut = $WscriptObj.CreateShortcut($ShortcutPath) Step #5: Add Target Path or other relevant arguments to shortcut variable $shortcut.TargetPath = $SourceFilePathĬool Tip: How to map network drive in PowerShell! Step #6: Use Save() method $shortcut.Save()Ībove program demonstrates, using PowerShell to create shortcut on desktop for user. When we run entire PowerShell script, it will create shortcut file to the user desktop with provided name. Step #1 Define source file location of Microsoft Edge $SourceFilePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"Ĭool Tip: Query Active Directory users info using PowerShell! Step #2: Define shortcut file location and name of shortcut file. You must have the Windows Script host on your computer to run the below script. Let’s look at given below PowerShell script to create shortcut for Microsoft Edge on desktop. Let’s consider a requirement to create a shortcut for Microsoft Edge using PowerShell script. 3 Conclusion PowerShell Create Shortcut to File
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |