Change powershell ICON

Jahangir Shah 1 Reputation point
2021-11-03T16:40:41.353+00:00

I have PowerShell script to open GUI form to perform administrative Task.
I want to change the Taskbar Icon of the GUI application created in .net using VS.
It is always PowerShell default Icon in the taskbar.
I want to change it to custom.
$Form1.ShowIcon = $True
$Form1.Icon = New-Object system.drawing.icon 'C:\test\M-icon.ico'

The above will only add the icon to the Gui form at top left, but not in taskbar.
Any help appreciated.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-11-03T18:00:51.103+00:00

    The very first icon in the EXE is the icon for the executable. However the window should show the icon associated with the form. But you're not creating your own app here but rather you're using Powershell so the PS icon is what is going to be shown.

    If this is for your own use then the easiest thing to do is right click the shortcut and change the icon that way. Of course you could change the icon associated with a PS1 files as well. But beyond that I'm not aware of any way to change a single PS1 file's icon to something else as that information isn't stored in the script, it is a resource in the program that runs it which you cannot change.

    In theory I guess you could call Win32 to change the icon being used for the script window that is running your script but honestly I don't see any benefit in doing that. Is the icon really that important? It is also important to note that this would have no impact on the icon shown in file explorer or any shortcut as that is metadata.

    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.