You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Get-PSSession with -ComputerName does not work #20995
This has already been stated in #6321 (and #17768?) but those were closed due to inactivity and as the bot closed those for housekeeping, I now create a new one.
Expected behavior
Id Name ComputerName ComputerType State ConfigurationName Availability-- ---- ------------ ------------ ----- ----------------- ------------1 WinRM1 dc01 RemoteMachine Opened Microsoft.PowerShell Available_(copied from a Windows machine executing the same command)_
Actual behavior
PS> Get-PSSession -ComputerName dc01 Get-PSSession: The term 'New-WSManSessionOption' is not recognized as a name of a cmdlet, function, script file, or executable program.Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Error details
No response
Environment data
Name Value
---------
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Kali GNU/Linux Rolling
Platform Unix
PSCompatibleVersions {1.0,2.0,3.0,4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Just out of curiosity - are you trying to get your sessions to [computername]
or a list of anybody's sessions ON [computername]
because it appears that this is trying to create an implicit WinRM session to [computerName] run get-psSession, and return the result
On my (windows) Machine I can connect to localhost from one PowerShell session using both wsman and ssl
#507 [|||] PS7 ~\Documents\blah> get-pssession
Id Name Transport ComputerName ComputerType State ConfigurationName Availability
-- ---- --------- ------------ ------------ ----- ----------------- ------------
1 Runspace1 WSMan localhost RemoteMachine Opened Microsoft.PowerShell Available
4 Runspace3 SSH localhost RemoteMachine Opened DefaultShell Available
If I ask from another powershell window
#506 [|||] PS7 ~\Documents\blah> Get-PSSession -ComputerName localhost
Id Name Transport ComputerName ComputerType State ConfigurationName Availability
-- ---- --------- ------------ ------------ ----- ----------------- ------------
2 Runspace1 WSMan localhost RemoteMachine Disconnected Microsoft.PowerShell Busy
It only shows me my WSMAN Session(s) even if try specifying the configuration name.
If I try to talk via SSL to get information on the SSL ones.
.
#507 [|||] PS7 ~\Documents\WindowsPowerShell\Modules\Image> Get-PSSession -ComputerName localhost -UseSSL
Get-PSSession: The remote session query failed for localhost with the following error message: The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig".
One of the PowerShell team did imply this wasn't by design in #6321 so the bot's closing it was automatic but seems the wrong thing to have done - it does seem to be all SSL not just SSL from Linux.
The benefit of an SSH based PowerShell remote session is that it works across multiple platforms (Windows, Linux, macOS).
For SSH based session you use the HostName or SSHConnection parameters to specify the remote computer and relevant connection information.
I would expect to use ComputerName ( rather like the NetBIOS/NetBEUI/LanManager computer name) for WinRM and HostName for SSH.
I would expect to use ComputerName ( rather like the NetBIOS/NetBEUI/LanManager computer name) for WinRM and HostName for SSL.
Unlike (e.g.) New-PsSession, Get-PsSession doesn't take -HostName
invoke-command -HostName localhost -ScriptBlock {get-Pssession} runs but returns nothing (even with -computername Localhost) - some ancient memory says that sessions over SSH don't know they are remote sessions which is why you can't (yet) do JEA over SSH.
This is a difficult one, Get-PSSession is very much tied into the WSMan stack and Get-PSSession -ComputerName ... is essentially hardcoded to do a WSMan enumeration POST to retrieve the information. The WSMan implementation on non-Windows is pretty restricted and cmdlets like New-WSManSessionOption are not included anymore. Even if the cmdlet existed it's going to fail on the next step when it tries to call Get-WSManInstance which is part of the same module and is also not included on non-Windows.
While yes this could theoretically work it's very likely it's never going to be worked on as the focus on the pwsh team is on ssh transport and not WSMan anymore. You can keep this open but be prepared for no activity to be done here, it requires some work from the pwsh team which is unlikely to happen in this area.
Just out of curiosity - are you trying to get your sessions to [computername]
or a list of anybody's sessions ON [computername]
Both, actually. For housekeeping reasons I want to close and/or reuse sessions that already exist and are no longer needed for their initial purpose.
I would expect to use ComputerName ( rather like the NetBIOS/NetBEUI/LanManager computer name) for WinRM and HostName for SSL.
As James O'Neill (@jhoneill) already pointed out this does not work as HostName isn't a valid option here.
My understanding is that WinRM is a windows only protocol and need to use SSH on MacOS and Linux.
As of what I found WinRM is based on the open standard WSMan which has to be installed manually inside pwsh. Doesn't it imply that if PowerShell hints that it needs those exact modules to run within a Linux-based system such calls as Get-PSSession -ComputerName $ComputerName would actually work?
[...] the pwsh team is on ssh transport and not WSMan anymore
Unfortunately, using the -UseSSL option also throws the error that "The term 'New-WSManSessionOption' is not recognized as a name of a cmdlet, function, script file, or executable program." - are there any special modules needed that don't come with pwsh and/or pwsh -Command -Install-Module -Name PSWSMan?
Unfortunately, using the -UseSSL option also throws the e
-UseSSL just means use https for WSMan, SSH is a completely different thing and doesn't really have the same concept as a persistent PSSession that Get-PSSession -ComputerName foo would return. There is no real concept of a long lived session with other protocols as they can only last for the lifetime of the connection. WSMan is special because you can have disconnected sessions and the state it stored on the service rather than the PowerShell process.
are there any special modules needed that don't c
In this case the WSMan enumeration code is part of Microsoft.WSMan.Management which is completely Windows only. Theoretcially someone could implement the New-WSManSessionOption and Get-WSManInstance so this works but I don't think that's going to happen.
Ultimately I think the -ComputerName parameter just needs to become Windows only in pwsh as it's not going to work on Linux without any large changes to WSMan support which the pwsh team has actively moved away from in recent years.
I don't want to be rude but displaying that it just doesn't work seems like an odd fix when the otherwise suggested solution to use option -UseSSL instead doesn't work either.
That’s not the suggested solution. SSL is not the same as SSH. What you are wanting to do requires code that does not work on non-Windows (the module is not shipped with the cmdlets needed) and getting it to work is not a trivial thing to do. If you want to remotely view PSSessions you need to run this on Windows where the WSMan client components are present.
The PR is there to make it clearer this parameter won’t work outside of Windows rather than the missing cmdlet error you get today.
Activity
jhoneill commentedon Jan 4, 2024
Just out of curiosity - are you trying to get your sessions to [computername]
or a list of anybody's sessions ON [computername]
because it appears that this is trying to create an implicit WinRM session to [computerName] run get-psSession, and return the result
On my (windows) Machine I can connect to localhost from one PowerShell session using both wsman and ssl
If I ask from another powershell window
It only shows me my WSMAN Session(s) even if try specifying the configuration name.
If I try to talk via SSL to get information on the SSL ones.
.
One of the PowerShell team did imply this wasn't by design in #6321 so the bot's closing it was automatic but seems the wrong thing to have done - it does seem to be all SSL not just SSL from Linux.
rhubarb-geek-nz commentedon Jan 4, 2024
My understanding is that WinRM is a windows only protocol and need to use SSH on MacOS and Linux.
According to Invoke-Command
I would expect to use ComputerName ( rather like the NetBIOS/NetBEUI/LanManager computer name) for WinRM and HostName for SSH.
jhoneill commentedon Jan 4, 2024
Unlike (e.g.)
New-PsSession,Get-PsSessiondoesn't take-HostNameinvoke-command -HostName localhost -ScriptBlock {get-Pssession}runs but returns nothing (even with-computername Localhost) - some ancient memory says that sessions over SSH don't know they are remote sessions which is why you can't (yet) do JEA over SSH.jborean93 commentedon Jan 4, 2024
This is a difficult one,
Get-PSSessionis very much tied into the WSMan stack andGet-PSSession -ComputerName ...is essentially hardcoded to do a WSMan enumeration POST to retrieve the information. The WSMan implementation on non-Windows is pretty restricted and cmdlets likeNew-WSManSessionOptionare not included anymore. Even if the cmdlet existed it's going to fail on the next step when it tries to callGet-WSManInstancewhich is part of the same module and is also not included on non-Windows.While yes this could theoretically work it's very likely it's never going to be worked on as the focus on the pwsh team is on ssh transport and not WSMan anymore. You can keep this open but be prepared for no activity to be done here, it requires some work from the pwsh team which is unlikely to happen in this area.
c2ho commentedon Jan 5, 2024
Both, actually. For housekeeping reasons I want to close and/or reuse sessions that already exist and are no longer needed for their initial purpose.
As James O'Neill (@jhoneill) already pointed out this does not work as
HostNameisn't a valid option here.As of what I found WinRM is based on the open standard WSMan which has to be installed manually inside pwsh. Doesn't it imply that if PowerShell hints that it needs those exact modules to run within a Linux-based system such calls as
Get-PSSession -ComputerName $ComputerNamewould actually work?Unfortunately, using the
-UseSSLoption also throws the error that "The term 'New-WSManSessionOption' is not recognized as a name of a cmdlet, function, script file, or executable program." - are there any special modules needed that don't come with pwsh and/orpwsh -Command -Install-Module -Name PSWSMan?jborean93 commentedon Jan 5, 2024
-UseSSLjust means use https for WSMan, SSH is a completely different thing and doesn't really have the same concept as a persistent PSSession thatGet-PSSession -ComputerName foowould return. There is no real concept of a long lived session with other protocols as they can only last for the lifetime of the connection. WSMan is special because you can have disconnected sessions and the state it stored on the service rather than the PowerShell process.In this case the WSMan enumeration code is part of
Microsoft.WSMan.Managementwhich is completely Windows only. Theoretcially someone could implement theNew-WSManSessionOptionandGet-WSManInstanceso this works but I don't think that's going to happen.Ultimately I think the
-ComputerNameparameter just needs to become Windows only in pwsh as it's not going to work on Linux without any large changes to WSMan support which the pwsh team has actively moved away from in recent years.jborean93 commentedon Jan 5, 2024
I've opened #21009 which emits a better error message that states
-ComputerNameis only for non-Windows.c2ho commentedon Jan 5, 2024
I don't want to be rude but displaying that it just doesn't work seems like an odd fix when the otherwise suggested solution to use option
-UseSSLinstead doesn't work either.jborean93 commentedon Jan 5, 2024
That’s not the suggested solution. SSL is not the same as SSH. What you are wanting to do requires code that does not work on non-Windows (the module is not shipped with the cmdlets needed) and getting it to work is not a trivial thing to do. If you want to remotely view PSSessions you need to run this on Windows where the WSMan client components are present.
The PR is there to make it clearer this parameter won’t work outside of Windows rather than the missing cmdlet error you get today.
microsoft-github-policy-service commentedon Dec 5, 2024
📣 Hey c2ho, how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback