-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Summary of the new feature/enhancement
Behind the scenes, background jobs use the remoting infrastructure, which means that $PSSenderInfo is populated in both cases, and $Host.Name contains ServerRemoteHost.
Currently, it isn't always possible to detect when code is executing in a background job vs. when it is running in a true remoting session - but it should be possible to do so, reliably.
Proposed technical implementation details (optional)
Currently, $PSSenderInfo.ConnectionString contains the fixed string http://localhost in background jobs, whereas in WinRM-based remoting sessions the URL contains the actual host name, port number, and client PowerShell version.
However, in SSH-based remoting sessions, the same fixed string is currently used, which should be considered a bug - see #11292
Once #11292 gets fixed, testing $PSSenderInfo.ConnectionString -eq 'http://localhost' could serve as the test for detecting background jobs, but that is both obscure and technically incorrect - though it could serve as a solution if there's a backward compatibility concern over changing the value for background jobs.
Since there is no actual network connection involved in the case of background jobs (I presume), I suggest simply setting .ConnectionString to '' (empty string).