官术网_书友最值得收藏!

Comment-based help

Another very important thing in PowerShell that you must know is that you can build the script with in-built help. There are no separate files that you need to maintain for your script. This is an amazing capability. There are two ways that you can write help lines in your PowerShell Script. You can either use a hash (#) in the line to indicate it's a help, or you can make use of the <#..#> block level comment. Let's use the following script to continue the discussion:

I specified a block level comment in <#..#> with some other interesting things. Once the parsing engine sees the block of lines inside <#..#>, it starts ignoring the text and knows that it is help comment. But pay special attention to the lines inside that block, which are started with a dot (.). It has a special meaning in PowerShell. PowerShell starts building your help file once it sees this dot. This is extremely helpful in PowerShell when you build a complex script that can be used by others. There is no need to maintain a separate help file. It is just like the help you seek for any other cmdlet available in PowerShell. You can simply now type the following and see the magic:

PS C:\>Get-Help .\PS_Comment.ps1 -detailed

So, you just built a help file that looks like the cmdlet help.

主站蜘蛛池模板: 鹰潭市| 山西省| 霍林郭勒市| 凌源市| 高密市| 资溪县| 淮安市| 岢岚县| 聂荣县| 依兰县| 新竹县| 涟水县| 图木舒克市| 乡城县| 合肥市| 安平县| 武冈市| 南宫市| 梁河县| 武宁县| 定兴县| 克山县| 孝昌县| 苗栗县| 南京市| 华池县| 文山县| 广西| 长乐市| 梅州市| 古浪县| 德钦县| 蒲江县| 仲巴县| 军事| 高邑县| 班戈县| 富宁县| 永兴县| 仙居县| 宜兴市|