Help, add custom icon file to Internet Shortcut (.url)

I am trying to find a way to add a custom icon file (example_icon.ico) to the Internet Shortcut (.url) file created previously by the following script…

Icon file is a custom icon file created in Photoshop and is not from a .exe or .dll

Custom Icon file resides in C:\Example_IconDir

Please assist.

 

$Shell = New-Object -ComObject (“WScript.Shell”)
$Favorite = $Shell.CreateShortcut($env:USERPROFILE + “\Desktop\Example_Shortcut.url”)
$Favorite.TargetPath = “https://example_url.com”;
$Favorite.Save()

 

$Favorite.IconLocation = "C:\Example_IconDir\....ico"

BTW: I did not know that right away … it took me 45 seconds to find it googling. :wink:

The shortcut also needs the .lnk extension. IconLocation property does not exist for the .url extension.

$Shell = New-Object -ComObject ("WScript.Shell")
$Favorite = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Example_Shortcut.lnk")
$Favorite.TargetPath = "https://example_url.com";
$Favorite.IconLocation = "C:\Example_IconDir\example_icon.ico"
$Favorite.Save()

I would agree with John Seerden in that you should use the .lnk extension. It makes all the difference, and it’s probably why Olaf lost 45 minutes of his life.

[pre]
[tommymaynard@srvx ~]$ $Shell = New-Object -ComObject (“WScript.Shell”)
[tommymaynard@srvx ~]$ $Favorite = $Shell.CreateShortcut($env:USERPROFILE + “\Desktop\Example_Shortcut.url”)
[tommymaynard@srvx ~]$ $Favorite | Get-Member

TypeName: System.__ComObject#{…}

Name MemberType Definition


Load Method void Load (string)
Save Method void Save ()
FullName Property string FullName () {get}
TargetPath Property string TargetPath () {get} {set}
[/pre]

vs.

[pre]
[tommymaynard@srvx ~]$ $Shell = New-Object -ComObject (“WScript.Shell”)
[tommymaynard@srvx ~]$ $Favorite = $Shell.CreateShortcut($env:USERPROFILE + “\Desktop\Example_Shortcut.lnk”)
[tommymaynard@srvx ~]$ $Favorite | Get-Member

TypeName: System.__ComObject#{…}

Name MemberType Definition


Load Method void Load (string)
Save Method void Save ()
Arguments Property string Arguments () {get} {set}
Description Property string Description () {get} {set}
FullName Property string FullName () {get}
Hotkey Property string Hotkey () {get} {set}
IconLocation Property string IconLocation () {get} {set}
RelativePath Property string RelativePath () {set}
TargetPath Property string TargetPath () {get} {set}
WindowStyle Property int WindowStyle () {get} {set}
WorkingDirectory Property string WorkingDirectory () {get} {set}
[/pre]

When .lnk is used, the properties, one of which is IconLocation, is returned by Get-Member.