当PowerShell 升级为4.0后,在高版本的PowerShell中怎样使用低版本的控制台?例如PowerShell 3.0 和PowerShell 2.0。
其实PowerShell.exe本身就具备了这个功能:
查看PowerShell 2.0的.NET 运行时
PS> powershell -Version 2.0 -Command "& { [environment]::Version }" Major Minor Build Revision ----- ----- ----- -------- 2 0 50727 7905
查看PowerShell 4.0的.NET 运行时
PS> powershell -Version 4.0 -Command "& { [environment]::Version }" Major Minor Build Revision ----- ----- ----- -------- 4 0 30319 34003
查看PowerShell 2.0 的命令条数
PS> powershell -Version 2.0 -Command "& { (get-command).count }" 410
查询PowerShell 4.0的命令条数
PS> powershell -Version 4.0 -Command "& { (get-command).count }" 1132
顺便验证下,高版本引入的PowerShell命令能在低版本上面运行不?答案是肯定的。
PS> powershell -Version 2.0 -Command "& { Invoke-WebRequest https://www.pstips.net }" Invoke-WebRequest : The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet, function, script file, or o perable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga in. At line:1 char:22 + & { Invoke-WebRequest <<<< https://www.pstips.net } + CategoryInfo : ObjectNotFound: (Invoke-WebRequest:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
本文链接: https://www.pstips.net/using-psv2-console-in-high-version.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!