@_ A couple of comments (well, it turned out to be a lot more…):
Gotcha#1 - If Notepad++ is already running then when you start a new instance of Notepad++.exe it sees that a copy is already running and will hand control to that. It does not pass along that it was started minimized. Thus Notepad++ will appear to start as a window or maximized if that’s what you already had it as.
Gotcha #2 - If Notepad++ is already running, but minimized, then attempts to start Notepad++ as minimized end up both passing control to the already running copy but also activating it to a normal or maximized window.
Gotcha 3 - There is another “gotcha” where if Notepad++ is running as a maximized window, you exit/close it, and then attempt to start it as minimized that Notepad++ will fire up as maximized.
The only thing works is for you to be running Notepad++ as a non-full screen windowed application, for you to exit/close it, and then to start it as minimized.
The second issue is your syntax for how to start Notepad++ seemed rather mangled. I don’t know if the mangling was your attempt to copy/paste a correct command into the forum or if attempted the wrong syntax to start with. I suspect you started with the wrong syntax as you mentioned “<ScriptBlock>,<No file>:line 1” etc. which is unexpected regardless of how you were trying to start Notepad++.
The syntax I used from PowerShell was:
Start-Process "C:\npp\npp858x64\notepad++.exe" -WindowStyle Minimized
I got the C:\npp\npp858x64\notepad++.exe part that is inside the quotes from Notepad++’ ? / Debug info... menu. A box or window will pop up. The second line of that box for me was:
Path : C:\npp\npp858x64\notepad++.exe
I copy/pasted the part into the command line that I used for testing this.
A normal installation of Notepad++ is usually in the C:\Program Files\Notepad++\notepad++.exe directory meaning people would use:
Start-Process "C:\Program Files\Notepad++\notepad++.exe" -WindowStyle Minimized
Again though, the gotchas mentioned above will apply regardless on if you try to start Notepad++ from Powershell, via a .lnk shortcut file that says “run minimized” or the command prompt’s START command with the /MIN option run run either the exe or shortcut. All of them will fail to be minimized if any of the gotchas I listed above apply.
To start a minimized Notepad++ you must:
Not already have Notepad++.exe running.
That when you exited/closed Notepad++ that it had been a windowed app (not maximized) regardless on if you may have had it minimized at the time you closed it.
It’s a rather narrow eye-hole in the needle but you can nail it 100% of the time if those two conditions exist.
If you absolutely must start a minimized copy of Notepad++ then I would:
Install a portable copy somewhere.
Rename the portable copy of Notepad++.exe to something else such as min-notepad.exe.
In your powershell script see if the min-notepad.exe process is running and if so, kill it and wait for it to terminate as we will then be updating the config.xml file.
In your powershell script inspect the config.xml file for your portable copy and see if the line for <GUIConfig name="AppPosition" ... has isMaximized="yes". If so, change that to be isMaximized="no" and save it.
Now you can start min-notepad.exe in minimized mode but there is still one more gotcha… You need to start min-notepad.exe with the -multiInst command line option to prevent it from locating a copy of Notepad.exe that is already running and passing control to it. The PowerShell command becomes:
Start-Process "C:\npp\npp858x64\min-notepad.exe" -ArgumentList @("-multiInst") -WindowStyle Minimized