win7 powershell 調試

win7默認的powershell版本爲2.0,此文所用的powershell版本爲:

Name                           Value                                                                                           
----                           -----                                                                                           
PSVersion                      5.1.14409.1005                                                                                  
PSEdition                      Desktop                                                                                         
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                         
BuildVersion                   10.0.14409.1005                                                                                 
CLRVersion                     4.0.30319.42000                                                                                 
WSManStackVersion              3.0                                                                                             
PSRemotingProtocolVersion      2.3                                                                                             
SerializationVersion           1.1.0.1    

win7下升級powershell教程:

https://blog.csdn.net/xiayuexingkong/article/details/93733047

調試方法:

1。新建test.ps1,然後在文件上點右鍵,選擇編輯,即可打開 powershell ise 編輯器。

輸入代碼:

function say($str)
{
echo "hello $str";
}


say "world";

 在 say "word"上按F9設置斷點,然後按F5運行腳本。

如果此時出現:

File C:\Users\...\Desktop\test.ps1 cannot be loaded because running scripts is disabled on this system. For more information, 
see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
    + CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

說明系統不允許執行powershell文件。

此時需要在命令窗口輸入 set-executionpolicy -executionpolicy unrestricted

此時會彈出窗口:

 選擇 yes to all.

再按F5即可調試腳本了。

微軟官方的ISE教程:

https://docs.microsoft.com/zh-cn/powershell/scripting/components/ise/how-to-debug-scripts-in-windows-powershell-ise?view=powershell-7

 

顯示標準變量的值


使用下列方法之一:
在腳本窗格中,將鼠標懸停在變量上,以在工具提示中顯示它的值。
在控制檯窗格中,鍵入變量的名稱並按 ENTER。
ISE 中的所有窗格始終位於同一作用域中。 因此,調試腳本時,你在控制檯窗格中鍵入的命令在腳本作用域中運行。 這樣,你便可以使用控制檯窗格查找變量的值,並調用僅在腳本中定義的函數。

自動完成命令輸入


在命令窗格或腳本窗格中,鍵入命令的幾個字符,然後按 TAB 以選擇所需補全文本。 如果有多個項以你最初鍵入的文本開頭,那麼繼續按 TAB,直到出現所需的項。 Tab 自動補全可以幫助鍵入 cmdlet 名、參數名、變量名、對象屬性名或文件路徑。 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章