Windows Unprivileged - Loading JEA Dynamically
Note that absolutely none of this is authoritative or directly based on relevant documentation. It’s mostly what I found and figured out and guessed and (in some cases) made up. Some of it may be wrong or dangerous or lead to disaster or confusion. I am not taking responsibility here for anything. Read and act on it at your own peril!
Put this into your $PROFILE to load all applicable JEA configurations by just typing jea.
function jea
{
$Global:OriginalWindowTitle = $Host.UI.RawUI.WindowTitle
$Host.UI.RawUI.WindowTitle = "JEA:"
(Get-ChildItem 'C:\Program Files\WindowsPowerShell\Modules\JEA\*.pssc').BaseName | ForEach-Object {
Import-PSSession (New-PSSession -ConfigurationName $_) -AllowClobber
$Host.UI.RawUI.WindowTitle += " $_"
}#foreach
}This will
- load all applicable JEA session configurations based on JEA configuration files in the C:\Program Files\WindowsPowerShell\Modules\JEA\ directory
- create a session for each JEA session configuration and import it
- change the window (or tab) title to JEA: and a list of all imported JEA sessions
- and throw a lot of error messages depending on PowerShell version.
You can then use all cmdlets directly but they will run in the appropriate JEA session. Only for images (.exe) you need to enter or invoke a pssession to run.
Note that it is very difficult to find the background sessions or get rid of them. So I suggest doing this only in a PowerShell session you don’t want to have back afterwards.