本文說明如何在 Windows IoT 與 Nano Server 上安裝 PowerShell。
部署於 Windows 11 IoT 平台
Windows 11 物聯網企業版內建 Windows PowerShell,用於部署 PowerShell 7。
# Replace the placeholder information for the following variables:
$deviceip = '<device ip address>'
$zipfile = 'PowerShell-7.5.4-win-arm64.zip'
$downloadfolder = 'U:\Users\Administrator\Downloads'
# The download location is local to the device.
# There should be enough space for the zip file and the unzipped contents.
# Create PowerShell session to target device
Set-Item -Path WSMan:\localhost\Client\TrustedHosts $deviceip
$S = New-PSSession -ComputerName $deviceIp -Credential Administrator
# Copy the ZIP package to the device
Copy-Item $zipfile -Destination $downloadfolder -ToSession $S
#Connect to the device and expand the archive
Enter-PSSession $S
Set-Location U:\Users\Administrator\Downloads
Expand-Archive .\PowerShell-7.5.4-win-arm64.zip
# Set up remoting to PowerShell 7
Set-Location .\PowerShell-7.5.4-win-arm64
# Be sure to use the -PowerShellHome parameter otherwise it tries to create a new
# endpoint with Windows PowerShell 5.1
.\Install-PowerShellRemoting.ps1 -PowerShellHome .
當您設定 PowerShell 遠程時,會收到錯誤訊息,且與裝置中斷連線。 PowerShell 必須重新啟動 WinRM。 現在,您可以連線到裝置上的PowerShell 7端點。
# Be sure to use the -Configuration parameter. If you omit it, you connect to Windows PowerShell 5.1
Enter-PSSession -ComputerName $deviceIp -Credential Administrator -Configuration PowerShell.7.5.4
Windows 11 IoT Core 在包含IOT_POWERSHELL功能時會添加 Windows PowerShell。 使用 Windows PowerShell 部署 PowerShell 7,步驟與 Windows 11 物聯網企業版相同。
要在出貨映像檔中新增最新的 PowerShell,請使用 Import-PSCoreRelease 指令將套件納入工作區,並將 OPENSRC_POWERSHELL 功能加入映像檔。
備註
針對 ARM64 架構,當您包含 IOT_POWERSHELL 時,不會新增 Windows PowerShell。 因此,ZIP 型安裝無法運作。 您必須使用 Import-PSCoreRelease 命令在映像中新增它。
在 Nano Server 上部署
這些指示假設 Nano Server 是具有 PowerShell 版本已在其上執行的「無頭部」操作系統。 如需詳細資訊,請參閱 Nano Server Image Builder 檔。
您可以使用兩種不同的方法來部署PowerShell二進位檔。
- 離線 - 掛接 Nano Server VHD,並將 zip 檔案的內容解壓縮到所掛接映像內的所選位置。
- 在線 - 透過 PowerShell 工作階段傳輸 zip 檔案,並將它解壓縮到您選擇的位置。
在這兩種情況下,您需要 Windows x64 ZIP 版本套件。 在 PowerShell 的「系統管理員」實例內執行命令。
PowerShell 的離線部署
- 使用您慣用的 zip 公用程式,將套件解壓縮到掛接 Nano Server 映射內的目錄。
- 卸載映像檔並啟動它。
- 連接至 Windows PowerShell 的內建實例。
PowerShell 的在線部署
使用下列步驟將PowerShell部署至 Nano Server。
# Replace the placeholder information for the following variables:
$ipaddr = '<Nano Server IP address>'
$credential = Get-Credential # <An Administrator account on the system>
$zipfile = 'PowerShell-7.5.4-win-x64.zip'
# Connect to the built-in instance of Windows PowerShell
$session = New-PSSession -ComputerName $ipaddr -Credential $credential
# Copy the file to the Nano Server instance
Copy-Item $zipfile C:\ -ToSession $session
# Enter the interactive remote session
Enter-PSSession $session
# Extract the ZIP file
Expand-Archive -Path C:\PowerShell-7.5.4-win-x64.zip -DestinationPath 'C:\Program Files\PowerShell 7'
支援的 Windows 版本
Microsoft 支援 PowerShell,直到 PowerShell 終止支援或 Windows 版本終止支援。
.NET SDK 的 Docker 映射包含最新版本的 PowerShell。 這些映像可從 Microsoft Artifact Registry 取得。
這些映像可能沒有最新的安全性更新。 Microsoft建議您將 OS 套件更新為最新版本,以確保套用最新的安全性更新。
這些映像僅供測試之用。 如果您需要生產工作負載的 Docker 映像,您應該自行建置和維護。
您可以執行 winver.exe來檢查您使用的版本。
安裝支援
Microsoft支援本檔中的安裝方法。 可能有其他第三方安裝方法可從其他來源取得。 雖然這些工具和方法可能正常運作,但Microsoft無法支持這些方法。
備註
本文中的安裝命令適用於最新穩定版本的 PowerShell。 若要安裝不同版本的 PowerShell,請調整 命令以符合您需要的版本。 下列連結會引導您前往 GitHub 上每個版本的最新版本頁面。
- 穩定版本 v7.5。x: https://aka.ms/powershell-release?tag=stable
- LTS 發佈版本 v7.4.x:https://aka.ms/powershell-release?tag=lts
- 預覽版 v7.6.0-preview。x: https://aka.ms/powershell-release?tag=preview
每個套件的下載連結都可以在 [發行] 頁面的 [ 資產 ] 區段中找到。 [資產] 區段可能會折疊,因此您可能需要按兩下以展開它。