Okay, in this one we are going down the rabbit hole of environment variables, User Vars, QAP and PowerShell, and this is a long read, so be warned.
The Problem
I use Environment Variables in several of my QAP favourites, especially the
%COMPUTERNAME% variable.
And to clean up in my menus and User Vars, I am slowly moving all of my scripts and command line (CMD) favourites over to PowerShell.
But PS knows nothing of the variable %COMPUTERNAME%, in PS that is the
$env:computername variable.
So the QAP favourite:
Application:cmd
Parameters:C:\SomeFolder\%COMPUTERNAME%\MyApp.exe
should then with PS just be:
Application:pwsh
Parameters:C:\SomeFolder\$env:computername\MyApp.exe
Nope, that won't work.
The shortcuts in QAP starts in CMD and parameters are passed as a string to PS, including Env Vars. So PS bombs out with an error because the file is not found.
The Solution, short term
The solution is to wrap the QAP favourite in a secondary pwsh instance ("PS host").
The drawback is that it takes slightly longer to run the shortcut.
The orginal:
pwsh -NoExit -Command "C:\SomeFolder\MyApp"
gets wrapped like this:
pwsh -Command "pwsh -NoExit -Command "C:\SomeFolder\MyApp""
Example
Consider this example from my ES-post.
I want different folders based on computer name for each Everything/ES installation (because of Shared Menus and some other factors not relevant here).
UserVar:
{tools}=C:\MyTools\Search\
{pwshopt}=-NoExit -Command
Type: Application
Basic Settings, Application: pwsh
Adv. Settings, Parameters: {pwshopt} "{tools}es.exe {Input:Enter file name or pattern} -highlight"
Turns into:
Basic Settings, Application: pwsh
Adv. Settings, Parameters: -Command "pwsh {pwshopt} "{tools}$env:computername\es.exe {Input:Enter file name or pattern} -highlight""
But the User Vars just keep working no matter how deep in the command line they are!
The Solution, in a possible future?
I've registered a feature request with Jean to be able to assign User Vars to Env Vars.
This would probably solve the wrapping thingy/problem.
Just define a User Var, {comp}=%COMPUTERNAME%, remove the wrap and replace $env.computername with {comp}.
PS would be none the wiser since QAP inserts the actual string from the User Var at run time.
(No pressure, Jean

)
Regards,
joeNOR
PS! If anyone has simpler and less crude solution to this, please comment!