create a url shortcut

David W 41 Reputation points
2021-07-20T05:34:40.427+00:00

Hi all...

I would like to create a one line powershell script to create a URL to go onto a users desktop...

the shortcut is a URL tho... : ms-settings:network-airplanemode

something like this
powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\Snipping Tool.lnk');$s.WorkingDirectory='C:\Windows\system32';$s.TargetPath='C:\Windows\system32\SnippingTool.exe';$s.Save()"

anyone able to help?

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,526 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue 37,021 Reputation points Microsoft Vendor
    2021-07-20T06:37:25.983+00:00

    Hi,

    You just need to set TargetPath to "ms-settings:network-airplanemode"

    powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\network-airplanemode.lnk');$s.TargetPath='ms-settings:network-airplanemode';$s.Save()"  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Evgenij Smirnov 541 Reputation points
    2021-07-20T08:36:42.32+00:00

    Hi,

    I wrote stuff up about the structure of the IE bookmarks (.url files) here: https://metabpa.org/projects/psbrowserbookmarks/about_browserbookmarks/

    With this knowledge, you shoule be able to compose the file directly, without resorting to system calls.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.