I've got a PowerShell script that creates shortcuts to network locations at login. Unfortunately, it's using an old low-res icon. It's not a big deal by any means, but I'd like to use the updated icons in later versions of Windows.
Here's the relevant portion of the function that creates the shortcut:
# Create the shortcut file
$shortcut = (New-Object -ComObject WScript.Shell).Createshortcut("$shortcutFolder\target.lnk")
$shortcut.TargetPath = $targetPath
if (
$shortcut.IconLocation = "%SystemRoot%\system32\SHELL32.DLL, 275"
$shortcut.Description = $targetPath
$shortcut.WorkingDirectory = $targetPath
$shortcut.Save()
# Set attributes on the files & folders
$desktopIni | Set-ItemProperty -Name Attributes -Value ([IO.FileAttributes]::System -bxor [IO.FileAttributes]::Hidden)
$shortcutFolder | Set-ItemProperty -Name Attributes -Value ([IO.FileAttributes]::ReadOnly)
As you can see, it's currently using Icon #275 in the SHELL32.DLL library. In Windows 7, the "proper" icon would be Icon #143 in imageres.dll. Is there any way to get the icon details from the OS like getting a reference to a Special folder in the Explorer namespace?