Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 668 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you comment out code in PowerShell?

#1
How do you comment out code in **PowerShell** (1.0 or 2.0)?
Reply

#2
It's the `#`.

See *[PowerShell - Special Characters And Tokens][1]* for special characters.

[1]:

[To see links please register here]

Reply

#3
Single line comments start with a [hash symbol](

[To see links please register here]

), everything to the right of the `#` will be ignored:

# Comment Here

In PowerShell 2.0 and above multi-line block comments can be used:

<#
Multi
Line
#>

You could use block comments to embed comment text within a command:

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

__Note:__ Because PowerShell supports [Tab Completion](

[To see links please register here]

) you need to be careful about copying and pasting `Space + TAB` before comments.





Reply

#4
You can make:

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

<#
for more lines
...
...
...
..
.
#>
Reply

#5
Within PowerShell ISE you can hit <kbd>Ctrl</kbd>+<kbd>J</kbd> to open the *Start Snipping* menu and select *Comment block*:

[![enter image description here][1]][1]


[1]:
Reply

#6
There is a special way of inserting comments add the end of script:
```
....
exit

Hi
Hello
We are comments
And not executed
```
Anything after `exit` is not executed, and behave quite like comments.
Reply

#7
Use a hashtag followed by a white space(!) for this:

# Comment here

Do not forget the white space here! Otherwise it can interfere with internal commands.

E.g., this is *not* a comment:

#requires -runasadmin

Reply

#8
You use the hash mark like this:

# This is a comment in PowerShell

Wikipedia has a good page for keeping track of how to do comments in several popular languages:

*[Comments][1]*

[1]:

[To see links please register here]

Reply

#9
Here

# Single line comment in PowerShell

<#
--------------------------------------
Multi-line comment in PowerShell V2+
--------------------------------------
#>

Reply

#10
In PowerShell V1 there's only `#` to make the text after it a comment.

<!-- language: lang-powershell -->

# This is a comment in PowerShell

In PowerShell V2 `<# #>` can be used for block comments and more specifically for help comments.

<!-- language: lang-none -->

#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:

[To see links please register here]

.EXAMPLE
Example 1
.EXAMPLE
Example 2
#>
Function blabla
{}

For more explanation about `.SYNOPSIS` and `.*` see [about_Comment_Based_Help][1].

Remark: These function comments are used by the `Get-Help` CmdLet and can be put before the keyword `Function`, or inside the `{}` before or after the code itself.

[1]:

[To see links please register here]



Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through