根据 OP 的说明编辑
如果您正在寻找链接中提到的每个 WMF 版本发布的 cmdlet...
'自 .Net 2.0 起可用'
'从 Powershell 3.0 开始可用'
...那么,TechNet 在这里提供:
PowerShell 1.0 Cmdlet
这些是可在 Windows PowerShell 1.0 中使用的 cmdlet 列表。
https://social.technet.microsoft.com/wiki/contents/articles/13769.powershell-1-0-cmdlets.aspx
PowerShell 2.0 Cmdlet
这些是可在 Windows PowerShell 2.0 中使用的 cmdlet 列表。
https://social.technet.microsoft.com/wiki/contents/articles/13876.powershell-2-0-cmdlets.aspx
PowerShell 3.0 Cmdlet
这些是 Windows 8 Developer Preview 中可用的 cmdlet、别名和函数。
https://social.technet.microsoft.com/wiki/contents/articles/4694.powershell-3-cmdlets.aspx
请注意,我没有找到类似上述 v4 - v6 (PowerShellCore) 的列表。
但是有这样的:
本主题列出了 Windows PowerShell 3.0、Windows PowerShell 4.0 和 Windows PowerShell 5.0 以及 Windows PowerShell 集成脚本环境 (ISE)、CIM 命令和工作流等特殊功能的系统要求。
https://docs.microsoft.com/en-us/powershell/scripting/setup/windows-powershell-system-requirements?view=powershell-5.1
考虑到你的追求。如果这是我。我开始的方法是使用适当的操作系统建立一组原始的 VM 客户端(或交给我们知道谁拥有它们的人),安装用于操作系统的 RTM WMF 版本并运行以下内容,保存到文件。
然后将该文件用作与代码进行比较的基础。意思是,在我的所有模块、函数和脚本上使用 Select-String 并匹配 cmdlet 名称以将比较文件中的其他属性获取到代码比较报告中。
任何 cmdlet 名称匹配,都可能是代码扫描的基线指示符,其中包含来自特定 PoSH 版本的 cmdlet。因此假设扫描的代码是在 OS WMF RTM 版本上编写的,或者是使用 -version 开关为给定的 WMF 版本编写的。
Report host OS, WMF and CLR version information
$OSVersion = (Get-WmiObject -Class Win32_OperatingSystem).Caption
Get-Command | Where CommandType -Match cmdlet |
Select Name, Version,
@{Name = 'PSCompatible';Expression = {$PSVersionTable.PSCompatibleVersions}},
@{Name = 'CLR';Expression = {$PSVersionTable.CLRVersion}},
@{Name = 'WSMan';Expression = {$PSVersionTable.WSManStackVersion}},
@{Name = 'Remoting';Expression = {$PSVersionTable.PSRemotingProtocolVersion}},
@{Name = 'OS';Expression = {$OSVersion}} |
Sort-Object Version | Format-Table -AutoSize
Name Version PSCompatible CLR WSMan Remoting OS
---- ------- ---------- --- ----- -------- --
Enable-SqlAlwaysOn 1.0 {1.0, 2.0, 3.0, 4.0...} 4.0.30319.42000 3.0 2.3 Microsoft Windows 10 Pro
Set-SqlAuthenticationMode 1.0 {1.0, 2.0, 3.0, 4.0...} 4.0.30319.42000 3.0 2.3 Microsoft Windows 10 Pro
Disable-SqlAlwaysOn 1.0 {1.0, 2.0, 3.0, 4.0...} 4.0.30319.42000 3.0 2.3 Microsoft Windows 10 Pro
Set-RuleOption 1.0 {1.0, 2.0, 3.0, 4.0...} 4.0.30319.42000 3.0 2.3 Microsoft Windows 10 Pro
Set-HVCIOptions 1.0 {1.0, 2.0, 3.0, 4.0...} 4.0.30319.42000 3.0 2.3 Microsoft Windows 10 Pro
...
Get summary cmdlets by cmdlet version
Get-Command | Group-Object Version | Sort-Object Name -Descending | Format-Table -AutoSize
Count Name Group
----- ---- -----
37 4.2.3 {Add-NTFSAccess, Add-NTFSAudit, Clear-NTFSAccess, Clear-NTFSAudit...}
33 4.0.6 {Add-AssertionOperator, AfterAll, AfterEach, AfterEachFeature...}
196 3.1.0.0 {ConvertFrom-SddlString, Format-Hex, Get-FileHash, Import-PowerShellDataFile...}
97 3.0.0.0 {Add-History, Add-PSSnapin, Clear-History, Connect-PSSession...}
...
然而,我对此的最后一个想法是,为什么要这样做?
我们知道旧代码将在更高版本中运行,而更高版本的特定模块/cmdlet/开关很可能无法在旧操作系统/PS 版本中本地运行。好吧,除非您手动破解内容,将它们复制到那里或使用远程处理将它们代理到那里,执行如下操作。
Use using current version cmdlets while on a legacy OS, i.e, Win7SP1 needing to use Test-NetConnection
$RemotePoSHModuleUNCFolder = '\\WS2012r2\$C\Windows\System32\WindowsPowerShell\v1.0\Modules'
$LocalhostPoSHModuleUNCFolder = 'C:\Windows\System32\WindowsPowerShell\v1.0\Modules'
'NetTCPIP','DnsClient','NetSecurity' `
| % {Copy-Item -Path $RemotePoSHModuleUNCFolder\$_ -Destination $LocalhostPoSHModuleUNCFolder}
'NetTCPIP','DnsClient','NetSecurity' `
| % {Import-Module -Name "C:\Windows\System32\WindowsPowerShell\v1.0\Modules\$_" -Verbose}
# Use cmdlet proxy, import module from remote machine WS201R2
$W2K12RemoteSession = New-PSSession -ComputerName 'WS2K12'
Import-Module NetTCPIP -PSSession $W2K12RemoteSession
MS 宣布 v2 折旧,如果 .Net 4x 在主机上,v2 会出现问题:
“不支持将 PowerShell 2.0 与 .NET Framework 4.0 一起使用。这是由于 CLR 4 的运行时激活策略发生了一些变化,这会阻止针对 CLR 2 构建的应用程序自动前滚到 CLR 4。”
这里有更多详细信息:https://msdn.microsoft.com/en-us/magazine/ee819091.aspx
除非您使用 V2 及以下版本的旧版操作系统,否则我不确定比较什么会为您买单。
但是您发布的内容听起来像是一个添加到 PSScriptAnalyzer 的好主意。