ScriptDeck icon indicating copy to clipboard operation
ScriptDeck copied to clipboard

Add -NoProfile to the startplugin.ps1 commandline

Open HarmVeenstra opened this issue 1 year ago • 5 comments

I see in my PowerShell logs that "C:\Program Files\PowerShell\7\pwsh.dll -ExecutionPolicy Bypass -File C:\Users\UserName\AppData\Roaming\Elgato\StreamDeck\Plugins\com.start-automating.scriptdeck.sdPlugin\StartPlugin.ps1" is being started. It also loads things from my profiles, which causes delays, and loading the profile is unnecessary. Could you add the -NoProfile option to the startup?

HarmVeenstra avatar Nov 20 '23 12:11 HarmVeenstra

@HarmVeenstra I don't know how I feel about this one.

On the one hand, profiles should be loaded when in user-mode PowerShell.

On the other hand, not everyone will want that (see this issue)

Got any ideas on how to thread this needle without the majority of PowerShell users being confused by profiles?

StartAutomating avatar Nov 25 '23 22:11 StartAutomating

I usually call scripts with a noprofile parameter to speed things up (Skipping unneeded profile things). I wrote a blog post about it, https://powershellisfun.com/2023/11/23/using-a-specific-powershell-profile-for-a-console-session-windows-terminal-powershell-ise-or-visual-studio-code/,in which I add checks if PowerShell is running interactively or not and that fixed the issue for me.

HarmVeenstra avatar Nov 25 '23 23:11 HarmVeenstra

@HarmVeenstra I think the "right" way to handle this would be with a global setting (aka changing the behavior for the whole plugin). What do you think of this approach? (I'd have to do some gruntwork)

Unfortunately in this case PowerShell is most definitely running interactively, and needs to be (in order to say, manipulate running windows).

StartAutomating avatar Dec 01 '23 02:12 StartAutomating

The PowerShell sessions being started by the plugin run as the user who's using StreamDeck, as far as I can imagine you start the powershell.exe (v5) or pwsh.exe (v7) with parameters. If so, adding -Noprofile as an extra argument would avoid loading the profile.

But you could also be starting powershell by using its dll, seen scripts being started like that too...

HarmVeenstra avatar Dec 01 '23 05:12 HarmVeenstra

I would also like to +1 the addition of a '-NoProfile' option. I understand the concerns and benefits, of adding it, so allowing the user to toggle this per 'button' would be a nice value addition & would appease to those who do & don't want to add this parameter to their scripts.

MartynKeigher avatar Feb 19 '24 17:02 MartynKeigher