powershell腳本的格式化


 Auto Formatting PowerShell in Visual Studio Code

1.安裝visual studio code

2.安裝powershell extension

3.打開腳本文件

4.F1,然后輸入format,找到format document的選項

但是這個用起來有點不太理想,傻乎乎的。

 

 

PowerShell Beautifier

通過導入powershell module進行操作,module提供了函數

  1. Download the PowerShell Beautifier utility. Clone it, zip it or get it from the PowerShell Gallery:
Install-Module -Name PowerShell-Beautifier
  1. Import the module. This takes a few seconds the first time but is fast thereafter.
Import-Module PowerShell-Beautifier.psd1
  1. Confirm it is loaded correctly:
Get-Help Edit-DTWBeautifyScript

很神奇的是,這里的import-module不需要每次都導入。直接集成在了內部

http://www.brianbunke.com/blog/2017/01/09/publishing-scripts/   參考這個文章看了一下,原來是把module放到了以下目錄,在啟動的時候自動加載

 C:\Users\clu\Documents\PowerShell\Modules

 

查看已經安裝的module

Get-InstalledModule

Version Name Repository Description
------- ---- ---------- -----------
1.2.5 PowerShell-Beautifier PSGallery PowerShell beautifier / code cleaner / p…0.0.1 WindowsCompatibility PSGallery This module Provides compatibility utili…

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM