Powershell 查看版本(Version)、更新版本.ps1

# 查看 Powershell 版本
# 查下面网址后面的 view=powershell-x.x
# https://learn.microsoft.com/zh-cn/powershell/scripting/overview

$PSVersionTable.PSVersion
$PSVersionTable.Item("PSVersion").ToString()

$PSVersionTable.PSVersion.Major

$V=$PSVersionTable.PSVersion; "$($V.Major).$($V.Minor).$($V.Build).$($V.Revision)"

Get-Host | Select-Object Version
Get-Host | Select-Object Version | Format-Table -HideTableHeaders

(Get-Host | Select-Object -ExpandProperty Version).ToString().Split('.')[0..1] -join '.'

$version = [System.Version]"$((Get-Host).Version.Major).$((Get-Host).Version.Minor)"
$version.ToString()

([System.Version]"$((Get-Host).Version.Major).$((Get-Host).Version.Minor)").ToString()

(Get-Host).Version.Major.ToString() + "." + (Get-Host).Version.Minor.ToString()

$version = (Get-Host).Version; "$($version.Major).$($version.Minor)"


# 更新 Powershell 版本
Function UpdatePowerShell{
    # 以管理员身份运行
    # https://www.delftstack.com/zh/howto/powershell/update-windows-powershell/

    # 1.先安装 PowerShellGet
    #   第一次更新需要执行以下步骤
    #   旧的 PowerShellGet 版本将停留在不同的位置,但新版本将优先于它。
    Install-Module PowerShellGet -Force -Verbose

    #   往后的更新只需执行以下步骤
    Update-Module PowerShellGet

    # 2.再安装winget
    #   https://github.com/microsoft/winget-cli/releases/download/v1.4.10173/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
    #   双击安装,如果提示”若要使该应用良好运行,请尝试启用一个Windows应用包“ 或 这句话的英文,就是安装成功了。
    #   检查所有可用的 PowerShell 安装程序
    winget search powershell

    # 3.安装最新的 Windows PowerShell (Core) 7 
    #   https://github.com/PowerShell/PowerShell/releases/download/v7.4.0-preview.1/PowerShell-7.4.0-preview.1-win-x64.msi
    winget install powershell

    #   升级当前的 Windows PowerShell 版本。
    winget upgrade powershell

    #   下载更新的 Windows PowerShell 包
    Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
}

# 在 CSDN 发布时使用风格,.ps1 风格首选: PHP, Haskell, Ruby, Swift, Crystal, 

# 查看 Powershell 版本
# 查下面网址后面的 view=powershell-x.x
# https://learn.microsoft.com/zh-cn/powershell/scripting/overview

$PSVersionTable.PSVersion
$PSVersionTable.Item("PSVersion").ToString()

$PSVersionTable.PSVersion.Major

$V=$PSVersionTable.PSVersion; "$($V.Major).$($V.Minor).$($V.Build).$($V.Revision)"

Get-Host | Select-Object Version
Get-Host | Select-Object Version | Format-Table -HideTableHeaders

(Get-Host | Select-Object -ExpandProperty Version).ToString().Split('.')[0..1] -join '.'

$version = [System.Version]"$((Get-Host).Version.Major).$((Get-Host).Version.Minor)"
$version.ToString()

([System.Version]"$((Get-Host).Version.Major).$((Get-Host).Version.Minor)").ToString()

(Get-Host).Version.Major.ToString() + "." + (Get-Host).Version.Minor.ToString()

$version = (Get-Host).Version; "$($version.Major).$($version.Minor)"


# 更新 Powershell 版本
Function UpdatePowerShell{
    # 以管理员身份运行
    # https://www.delftstack.com/zh/howto/powershell/update-windows-powershell/

    # 1.先安装 PowerShellGet
    #   第一次更新需要执行以下步骤
    #   旧的 PowerShellGet 版本将停留在不同的位置,但新版本将优先于它。
    Install-Module PowerShellGet -Force -Verbose

    #   往后的更新只需执行以下步骤
    Update-Module PowerShellGet

    # 2.再安装winget
    #   https://github.com/microsoft/winget-cli/releases/download/v1.4.10173/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
    #   双击安装,如果提示”若要使该应用良好运行,请尝试启用一个Windows应用包“ 或 这句话的英文,就是安装成功了。
    #   检查所有可用的 PowerShell 安装程序
    winget search powershell

    # 3.安装最新的 Windows PowerShell (Core) 7 
    #   https://github.com/PowerShell/PowerShell/releases/download/v7.4.0-preview.1/PowerShell-7.4.0-preview.1-win-x64.msi
    winget install powershell

    #   升级当前的 Windows PowerShell 版本。
    winget upgrade powershell

    #   下载更新的 Windows PowerShell 包
    Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值