PowerShell DSC Resource to create shortcut file (LNK file).
You can install Resource through PowerShell Gallery.
Install-Module -Name DSCR_Shortcut
- cShortcut PowerShell DSC Resource to create shortcut file.
-
[string] Ensure (Write):
- Specify whether or not a shortcut file exists
- The default value is
Present
. { Present | Absent }
-
[string] Path (Key):
- The path of the shortcut file.
- If the path ends with something other than
.lnk
, The extension will be added automatically to the end of the path
-
[string] Target (Required):
- The target path of the shortcut.
-
[string] Arguments (Write):
- The arguments of the shortcut.
-
[string] WorkingDirectory (Write):
- The working directory of the shortcut.
-
[string] WindowStyle (Write):
- You can select window style. { normal | maximized | minimized }
- The default value is
normal
-
[string] Description (Write):
- The description of the shortcut.
-
[string] Icon (Write):
- The path of the icon resource.
-
[string] HotKey (Write):
- HotKey (Shortcut Key) of the shortcut
- HotKey works only for shortcuts on the desktop or in the Start menu.
- The syntax is:
"{KeyModifier} + {KeyName}"
( e.g."Alt+Ctrl+Q"
,"Shift+F9"
) - If the hotkey not working after configuration, try to reboot.
-
[string] AppUserModelID (Write):
- Specifies AppUserModelID of the shortcut
- About AppUserModelID, See Microsoft Docs.
https://docs.microsoft.com/en-us/windows/win32/shell/appids
- Example 1: Create a shortcut to the Internet Explore InPrivate mode to the Administrator's desktop
Configuration Example1
{
Import-DscResource -ModuleName DSCR_Shortcut
cShortcut IE_Desktop
{
Path = 'C:\Users\Administrator\Desktop\PrivateIE.lnk'
Target = "C:\Program Files\Internet Explorer\iexplore.exe"
Arguments = '-private'
}
}
- Example 2: Specifies All Properties
Configuration Example2
{
Import-DscResource -ModuleName DSCR_Shortcut
cShortcut IE_Desktop
{
Path = 'C:\Users\Administrator\Desktop\PrivateIE.lnk'
Target = 'C:\Program Files\Internet Explorer\iexplore.exe'
Arguments = '-private'
WindowStyle = 'maximized'
WorkingDirectory = 'C:\work'
Description = 'This is a shortcut to the IE'
Icon = 'shell32.dll,277'
HotKey = 'Ctrl+Shift+U'
AppUserModelID = 'Microsoft.InternetExplorer.Default'
}
}
Get a lnk file properties.
- Syntax
Get-Shortcut [-Path] <string> [-ReadOnly]
Create a lnk file.
- Syntax
New-Shortcut [-Path] <string> [-TargetPath] <string> [-Description <string>] [-Arguments <string>] [-WorkingDirectory <string>] [-Icon <string>] [-HotKey <string>] [-WindowStyle {<normal> | <maximized> | <minimized>}] [-AppUserModelID <string>] [-PassThru] [-Force]
Update properties of an exist lnk file.
- Syntax
Update-Shortcut [-Path] <string> [-TargetPath] <string> [-Description <string>] [-Arguments <string>] [-WorkingDirectory <string>] [-Icon <string>] [-HotKey <string>] [-WindowStyle {<normal> | <maximized> | <minimized>}] [-AppUserModelID <string>] [-PassThru] [-Force]
- Class libraries are included as pre-compiled binaries. This greatly improves module load times. #14
- Export useful functions.
Get-Shortcut
,New-Shortcut
,Update-Shortcut
- Fixed an issue that the test fails when http / https URLs is specified in Target.
- [Regression] Fixed an issue where environment variables in a shortcut file would be unintentionally expanded.
- [Regression] Fixed an issue where environment variables in a shortcut file would be unintentionally expanded.
- Fixed an issue where
HotKey
would not be determined correctly between multiple different keyboard layouts. - You can now specify the Fn-key for
HotKey
by itself. (In previous versions, it had to be combined with modifier keys.) - Add Unit & Integration tests.
- v1 of the module initializes properties not specified in the configuration when updating an existing shortcut file, but v2 preserves them.
- Add
AppUserModelID
property.
You can use this to control the grouping of the taskbar. See Microsoft Docs for more information.
https://docs.microsoft.com/en-us/windows/win32/shell/appids
- For better performance and future scalability, The internal interface has been changed from
WshShortcut
toIShellLink
. - Avoid positional parameters.
- Fix minor issues.
- Changed not to test for properties not explicitly specified.
- Fix PSSA issues.
- Remove unnecessary files in the published data.
- Fixed issue that the Test-TargetResource always fails when the Target contains environment variables. #9
- Fixed issue that the Test-TargetResource may fails when the Icon is specified.
- Fixed issue that the Test-TargetResource always fails when the HotKey is not specified. #8
- Improved verbose messages.
- Change type of
HotKey
to[string]
- Add
Description
property #1 - Add
HotKey
property #2 - Add
Icon
property #3