天天看點

【Windows10 IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

注:若要使用裝有Windows10 IoT

Core裝置啟動PS會話,首先需要在主機電腦與裝置之間建立信任關系。

​啟動 Windows IoT

核心版裝置後,與該裝置相連的螢幕上将顯示一個 IP 位址:

(<code>![Windows 10 IoT 核心版上的 CoreDefaultApp](/content/images/DefaultApp.png) 可在Windows10 IoT Core Watcher實用工具中找到相同資訊。</code>)

【Windows10&amp;nbsp;IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

IoT Core啟動界面

​在本地電腦上啟動管理者 PS

控制台。

(在 Windows“開始”菜單旁的“搜尋 Web 和

Windows”文本框中鍵入“powershell”)

【Windows10&amp;nbsp;IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

以管理者身份啟動 PS,請右鍵單擊“Windows

PowerShell”項并選擇“以管理者身份運作”:

【Windows10&amp;nbsp;IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

Powershell控制台:

【Windows10&amp;nbsp;IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

主界面

注:需要在桌面上啟動 WinRM 服務以啟用遠端連接配接,在 Powershell 控制台中,輸入:

net start WinRM​

​在 Powershell

控制台中,鍵入以下指令,進而使用相應的值替代 <code>:</code>

<code>​</code>Set-Item

WSMan:\localhost\Client\TrustedHosts -Value

 輸入 Y 以确認更改。

現在,使用 Windows IoT 核心版裝置啟動會話,在管理者身份 PS 控制台中,鍵入:

​Enter-PSSession

-ComputerName -Credential \Administrator

在憑據對話框中,輸入以下預設密碼:p@ssw0rd

【Windows10&amp;nbsp;IoT開發系列】PowerShell的相關配置 1.​啟動 PowerShell (PS) 會話 2.Visual Studio 遠端調試程式疑難解答3.​配置 Windows IoT 核心版裝置4.已知問題與解決方法

更改賬戶密碼:在 PowerShell 連接配接中發出以下指令

​net

user Administrator [new password]

完成操作後,需要使用具有新憑據的 Exit-PSSession 和 Enable-PSSession 來建立新的

PowerShell 會話。  

Exit-PSSession Enter-PSSession -ComputerName -Credential

\Administrator​

為了能夠從 Visual Studio 2015 部署應用程式,需確定 Visual Studio 遠端調試程式正在

Windows IoT 核心版裝置上運作。遠端調試器應在計算機啟動時自動啟動,若要檢查啟動情況,請使用 tlist 指令列出 powershell 中所有正在運作的程序,應有兩個

msvsmon.exe 的執行個體正在裝置上運作。  

在長時間都處于非活動狀态後,Visual Studio 遠端調試器可能會出現逾時。若Visual Studio 無法連接配接到

Windows IoT 核心版裝置,請嘗試重新啟動裝置。

​更改“計算機名”,請使用 setcomputername 實用工具:

setcomputername

​重新啟動裝置使更改生效,使用

shutdown 指令:

shutdown /r /t 0

​重新啟動後,由于計算機名稱已更改,需要重新運作此指令,以便連接配接到裝置:

 Set-Item

​問題:PowerShell 安全政策中的一個已知 Bug

會導緻遠端會話内的清單出現以下問題: 

① Get-Help 傳回異常比對項。

② 指定子產品上的 Get-Command 将傳回空指令清單。

③ 從以下任意子產品運作 cmdlet 将引發

CommandNotFoundException:

Appx、NetAdapter、NetSecurity、NetTCPIP、PnpDevice。

④ 上述任意子產品上的 Import-Module 将引發

PSSecurityException 異常(包含 UnauthorizedAccess)。子產品自動加載似乎也不起作用。

解決方法: 将遠端 PowerShell

會話内的執行政策修改為“RemoteSigned”。

問題:有時,某些子產品中的

cmdlet(如 NetAdapter)不可見。例如,Get-Module NetAdapter 将傳回一個空清單。

解決方法:

将“-Force”參數與

Import-Module 結合使用。例如,Import-Module

NetAdapter -Force。 

 問題:

将執行政策設定為“AllSigned”時會中斷 PS

遠端控制。建立遠端會話的後續嘗試均失敗,并且 SecurityException 正在加載

Typesv3.ps1xml。 

 解決方法:

使用 winrs.exe 還原 Powershell 執行政策:  

更改控制台代碼頁 Chcp

65001

 ②

登入到遠端 cmd.exe shell Winrs.exe

-r: -u: -p: cmd.exe 

③ 在遠端

cmd.exe 内,修改相應的系統資料庫項 reg

add

HKLM\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

/v ExecutionPolicy /d RemoteSigned /f 

④ 退出遠端

cmd.exe 會話 exit

本文​主要資源來自Windows

開發中心。

繼續閱讀