Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

TCC and PowerShell shared environment

Aug
1,917
68
I discovered something by accident today.

I am using;
Code:
c:\users\jlc\utils>ver

TCC  24.02.46 x64   Windows 7 [Version 6.1.7601]

In my Powershell profile, C:\Users\jlc\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1, I have, for example, the following function;
Code:
function CDate
{
  param ([string]$theDate)
  $bdate = Get-Date -format D $theDate
  $env:cdate=$bdate
}

If I do the following from TCC;
Code:
c:\users\jlc\utils>pshell /c

c:\users\jlc\utils>pshell /s "cdate %_isodate"

c:\users\jlc\utils>echo %cdate
Saturday, March 30, 2019

...the environment variable that I just set in PowerShell via my CDate function is also set in TCC.

Now, if I do;
Code:
c:\users\jlc\utils>pshell /c
followed by;
Code:
c:\users\jlc\utils>pshell /s "$env:cdate"
Saturday, March 30, 2019
...the environment variable is still set in Powershell, even though I have closed the Powershell interpreter.

From TCC, if I do;
Code:
c:\users\jlc\utils>set cdate=jajb

c:\users\jlc\utils>echo %cdate
jajb

...then from TCC;
Code:
c:\users\jlc\utils>pshell /s "$env:cdate"
jajb

...the environment variable that I just set in TCC has also been set in PowerShell.

I have no problem with this, as it eliminates the use of @execstr for getting the output of a PowerShell function, but is this WAD?

Joe
 
It doesn't surprise me. An environment belongs to a process. In all the above, the only process is TCC. If you were invoking POWERSHELL.EXE it would be a different story.
 
That's not necessarily true. Usually, Windows programs do not modify their own environment block.
Preparing new environment block for spawned processes is more common.
 
That's not necessarily true. Usually, Windows programs do not modify their own environment block.
Preparing new environment block for spawned processes is more common.
TCC is not spawning a process. There is no other process. TCC accesses PowerShell capabilities via a DLL (loaded in the TCC process). Any environment changes happen to TCC's environment.
 
Back
Top