Jak skomentować kod w PowerShell?

Jak skomentować kod w PowerShell (1.0 lub 2.0)?

Author: Peter Mortensen, 2011-09-08

7 answers

W PowerShell V1 jest tylko # aby tekst po nim był komentarzem.

# This is a comment in Powershell

W PowerShell V2 <# #> może być używany do komentarzy blokowych, a dokładniej do komentarzy pomocy.

#REQUIRES -Version 2.0

<#
.SYNOPSIS
    A brief description of the function or script. This keyword can be used
    only once in each topic.
.DESCRIPTION
    A detailed description of the function or script. This keyword can be
    used only once in each topic.
.NOTES
    File Name      : xxxx.ps1
    Author         : J.P. Blanc ([email protected])
    Prerequisite   : PowerShell V2 over Vista and upper.
    Copyright 2011 - Jean Paul Blanc/Silogix
.LINK
    Script posted over:
    http://silogix.fr
.EXAMPLE
    Example 1
.EXAMPLE
    Example 2
#>
Function blabla
{}

Aby dowiedzieć się więcej o .SYNOPSIS i .* Zobacz about_Comment_Based_Help.

Uwaga: te komentarze funkcji są używane przez CmdLet Get-Help i mogą być umieszczone przed słowem kluczowym Function, lub wewnątrz {} przed lub po samym kodzie.

 1113
Author: JPBlanc,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-23 13:18:38

Używasz znaku skrótu w ten sposób

# This is a comment in Powershell

Wikipedia ma dobrą stronę do śledzenia, jak robić komentarze w kilku popularnych językach

Http://en.wikipedia.org/wiki/Comparison_of_programming_languages_ # Comments

 94
Author: adamleerich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-09-08 02:52:27

To #.

Zobacz PowerShell - znaki specjalne i żetony dla znaków specjalnych.

 38
Author: falcojr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-05 09:25:01

Komentarze w jednej linii rozpoczynają się symbolem hash , wszystko po prawej stronie # zostanie zignorowane:

# Comment Here

W PowerShell 2.0 i nowszych blokach wielowierszowych można używać komentarzy:

<# 
  Multi 
  Line 
#> 

Możesz użyć blokowania komentarzy, aby osadzić tekst komentarza w Komendzie:

Get-Content -Path <# configuration file #> C:\config.ini

Uwaga: ponieważ PowerShell obsługuje uzupełnianie kart musisz uważać na kopiowanie i wklejanie Space + TAB przed komentowaniem.

 26
Author: Alexander,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-17 08:29:49

Tutaj

# Single line comment in Powershell

<# 
--------------------------------------
Multi-line comment in PowerShell V2+ 
-------------------------------------- 
#>
 15
Author: Vic,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-09-17 08:00:46

W PowerShell ISE możesz nacisnąć Ctrl+J aby otworzyć Rozpocznij wycinanie menü i wybierz komentuj blok:

Tutaj wpisz opis obrazka

 8
Author: Martin Brandl,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-10-06 11:22:56

Możesz zrobić:

 (Some basic code) # Use "#" after a line and use:

 <#
    for more lines
    ...
    ...
    ...
    ..
    .
 #>
 3
Author: Mister X CT,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-03-02 10:53:56