# this password is required to be able to load and use the certificate later $Password = Read-Host-Prompt'Enter Password'-AsSecureString # certificate will be exported to this file $Path = "$Home\Desktop\myCert.pfx"
# certificate must be in your personal certificate store $cert = Get-ChildItem-Path Cert:\CurrentUser\My -CodeSigningCert | Out-GridView-Title'Select Certificate'-OutputMode Single $cert | Export-PfxCertificate-Password$Password-FilePath$Path
# path to folder to create a catalog file for # (make sure it exists and isn't too large) $path = "$Home\Desktop" # path to catalog file to be created $catPath = "$env:temp\myDesktop.cat" # create catalog New-FileCatalog-Path$path-CatalogVersion2.0-CatalogFilePath$catPath
# get the URL for the latest PowerShell 6 release $url = "https://github.com/PowerShell/PowerShell/releases/latest?dummy=$(Get-Random)" $request = [System.Net.WebRequest]::Create($url) $request.AllowAutoRedirect=$false $response = $request.GetResponse() $realURL = $response.GetResponseHeader("Location") $response.Close() $response.Dispose()
# get the current version from that URL $v = ($realURL-split'/v')[-1]
# create the download URL for the release of choice # (adjust the end part to target the desired platform, architecture, and package format) $platform = "win-x64.zip" $static = "https://github.com/PowerShell/PowerShell/releases/download" $url = "$static/v$version/PowerShell-$version-$platform"
这段代码生成 ZIP 格式的 64 位 Windows 版下载链接。如果您需要不同的发行版,只需要调整 $platform 中定义的平台部分。
当获得了下载链接,您可以通过它自动完成剩下的步骤:下载 ZIP 文件,取消禁用并解压,然后执行 PowerShell 6:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# define the place to download to $destinationFile = "$env:temp\PS6\powershell6.zip" $destinationFolder = Split-Path-Path$destinationFile
# create destination folder if it is not present $existsDestination = Test-Path-Path$destinationFolder if ($existsDestination-eq$false) { $null = New-Item-Path$destinationFolder-Force-ItemType Directory }
# get all releases Invoke-RestMethod-Uri https://github.com/PowerShell/PowerShell/releases.atom -UseBasicParsing | # sort in descending order Sort-Object-Property Updated -Descending | # pick the first (newest) release and get a link Select-Object-ExpandProperty Link -First1 | # pick a URL Select-Object-ExpandProperty HRef
# add a random number to the URL to trick proxies $url = "https://github.com/PowerShell/PowerShell/releases/latest?dummy=$(Get-Random)"
$request = [System.Net.WebRequest]::Create($url) # do not allow to redirect. The result is a "MovedPermanently" $request.AllowAutoRedirect=$false # send the request $response = $request.GetResponse() # get back the URL of the true destination page, and split off the version $realURL = $response.GetResponseHeader("Location") # make sure to clean up $response.Close() $response.Dispose()