Hi Olaf,
I think my earlier comparison of powershell with java is possibly not a great one. ChatGpt explains that java is targeted at application development where as powershell is targeted towards system administration, this said I think there are similarities in concept between java write once run anywhere (WORA) and powershell Universal code execution model (UCEM) models?
In my opinion, the earlier referenced youtube video by Jeffrey Snover and Jason Helmick powershell zero to hero full course coupled with Learn Windows Powershell in month of lunches by Don Jones/Jeffery D. Hicks book are excellent/legendary! But it had not been obvious to me what was meant by the use of the term/word “code”.
I believe Invoke-Command run on source computer loads .net and powershell on remote computer and sends powershell command line syntax (also referred as syntatix sugar) to the remote computer; byte/object code/executable code is not sent to remote computer. This as possibly seen in the following wireshark network trace:
ChatGpt search: “invoke-command compatibility PowerShell 5 to PowerShell 3” also explains:
- Use basic PowerShell features: Stick to basic PowerShell language features and common cmdlets that are available across both versions.
For both above reasons I think Invoke-Command sends powershell command line syntax (also referred to as “code”) to remote computer, but specifically no byte/object code/executable code is sent to remote computer. The panacea of UCEM is possibly downplayed because of rapid evolution of Powershell versions and mixed version environments?
If you don’t have MS Exchange on your source computer but are invoking an MS Exchange command on remote computer, the objects generated on remote computer need to serialised and then de-serialised on source computer using a common set of object types that are unlikely to ever change, this is necessary because the source computer doesn’t have MS Exchange installed on it so returning the raw MS Exchange object types would not be recognized on source computer.
Implicit remoting (uses Invoke-command in the background), it enables you to import a signature copy of the remote computer command (using Import-PSSession) and run as if they were local to source computer; this is explained PowerShell For Beginners Full Course | PowerShell Beginner tutorial Full Course - YouTube
From my Centos host $PSVersionTable lists supported previous versions:
[root@centos83 ~]# cat /etc/redhat-release
CentOS Linux release 8.5.2111
[root@centos83 ~]# pwsh
PowerShell 7.3.6
PS /root> $PSVersionTable
Name Value
PSVersion 7.3.6
PSEdition Core
GitCommitId 7.3.6
OS Linux 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS /root> $PSVersionTable | select-object -ExpandProperty PSCompatibleVersions
Major Minor Build Revision
1 0 -1 -1
2 0 -1 -1
3 0 -1 -1
4 0 -1 -1
5 0 -1 -1
5 1 10032 0
6 0 0 -1
6 1 0 -1
6 2 0 -1
7 0 0 -1
7 1 0 -1
7 2 0 -1
7 3 6 -1
PS /root>