PowerShell / PowerShell/Win32-OpenSSH
How can I check if Microsoft.PowerShell_profile.ps1 is running from an SSH session?
Nobody has claimed this yet.
- Dominant language
- No language data
- Stars
- 8.3k
- Forks
- 819
- PR merge metrics
- No merged PRs in 30d
Description
I'm trying to work around a bug where -NoProfile -NoLogo is not respected (#1677) when using pwsh.exe (Core) and logging remotely in via SSH. The way I tried to do it was by using the following in the very beginning of my Microsoft.PowerShell_profile.ps1 profile.
function IsInteractive {
$non_interactive = '-command', '-c', '-encodedcommand', '-e', '-ec', '-file', '-f'
-not ([Environment]::GetCommandLineArgs() | Where-Object -FilterScript {$PSItem -in $non_interactive})
}
# No point of running this script if not interactive
if (-not (IsInteractive)) {
exit
}
...
However, this doesn't seem to work with a remote SSH, because when using [Environment]::GetCommandLineArgs() with pwsh.exe, all you get back is:
C:\Program Files\PowerShell\6\pwsh.dll
regardless whether or not you are in an "interactive" session.
Any better ideas how to check if the profile is running from a remote SSH session?
UPDATE: Apparently the *.dll thing is a bug in .NET 5.0 as reported here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the profile snippet using Microsoft.PowerShell_profile.ps1 and [Environment]::GetCommandLineArgs(), then review the referenced #1677 issue and the linked .NET 5.0 runtime report. The issue does not identify a target file, test, or agreed implementation, so completion criteria are not established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli, networking
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100