Hi all,
I have a Windows 10 system that I installed PS 7 on. I am connecting to that system remotely using enter-pssession. I have a script that runs gets system uptime using Get-Uptime.
The problem is Get-Uptime wasnt in PS5, and everytime I connect with enter-pssession or invoke-command, i get the ps5 console, and it doesnt know Get-Uptime. Is there a way to connect to the PS 7 console ?
What is Get-Uptime? If I’m not wrong it’s not a default function or cmdlet of either version 5.1 or version 7. I’d assume it is a local function you want to call remotely, right?
This has nothing to do with connecting remotely to Windows PowerShell or PowerShell core.
I’d recommend to use Get-CimInstance to query remote mashines. If you want to query more than just one CIM clas you may use a common CIM session for all queries to reduce the connections and speed up your code.
In quick n’ dirty it would look something like this
One more thing,
When I Enter-Pssession on the remote computer, and check $PSVersionTable, its 5.1. I can run Windows Terminal on that system using PS7, and Get-Uptime runs then, so I was hoping to be able to somehow connect like that.
I updated my answer above with a snippet to show how to get the uptime when you already have the LastBootupTime. So you don’t need another function.
You actually don’t need to use Invoke-Command for CIM cmdlets. They’re all capable of implicit remoting using either the parameter -ComputerName or -CimSession
You connect to a remote computer and start PWSH inside this remote connection? Really?
But anyway … you don’t need that.
How did you define that function on the remote system?
While I’m sure that’s possible I never tried that and don’t know how that works, sorry.
Who ever said I did that? What I actually said was I can run Windows Terminal on that system using PS7…implying LOCALLY??? Sorry if that was over your head!
so what we are saying is…even though that system has Get-Uptime as I can run it when i am sitting at the console, you cant run it against that system remotely? Interesting.
You have to specify the configuration you want to connect to. If it’s not available, run Enable-PSRemoting in the version of PowerShell you want to connect to on the remote machine first.
I actually was not aware of it until now that Get-Uptime is a built in cmdlet of PowerShell version 7.x. Since I use a self written function with the same name for about 10 years I never noticed that MSFT actually included that in version 7.
$session = New-PSSession -ComputerName sk-1st -ConfigurationName PowerShell.7
New-PSSession: [sk-1st] Connecting to remote server sk-1st failed with the following error message : The WS-Management service cannot process the request. Cannot find the PowerShell.7 session configuration in the WSMan: drive on the sk-1st computer. For more information, see the about_Remote_Troubleshooting Help topic.
any ideas on why that system doesn’t show the PSVersion as 7 for the PowerShell7?