问题描述
Windows10 默认使用PowerShell 5,在安装PowerShell 7之后,不知道该怎么使用/切换到PowerShell 7。
如何使用PowerShell 7
Windows10 新安装的PowerShell 7不会取代旧版本,而是与旧版本并存,有两种方法能够使用PowerShell 7。
方法1:用PowerShell 7运行脚本
还从原来的PowerShell或者Windows Terminal启动,启动后提示信息应该是:
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
尝试新的跨平台 PowerShell https://aka.ms/pscore6
这说明当前使用的是旧版本PowerShell 5。若想以PowerShell 7运行脚本,则使用pwsh
命令,例如:pwsh .\test.ps1
方法2:直接使用PowerShell 7程序
安装PowerShell 7后,在开始-所有应用
里面就会出现一个新的软件PowerShell 7(x64)
,直接运行这个软件就是PowerShell 7。
如果使用Windows Terminal,在顶部的下拉菜单里选择PowerShell
,如图
若命令行提示PowerShell 7.3.2
就说明当前用的是PowerShell 7。
设置为Windows Terminal默认项
在Windows Terminal设置默认启动项即可