The first is if you simply want to uncomment some code-lines. In this case, you can surround them with an if-statement like
if ($false) {
disabled-command
}
This can be useful when developing.
This first approach has that advantage - or disadvantage - that the disabled code must be syntactically correct.
The seconds approach, utilizes the multi-line contant construction of PowerShell. Simply surround the lines with @' and '@ -
@'
whatever
'@ > $null
whatever can be anything except that the line must not start with '@. $null is used to write the string into the big bit void. So this approach is good for writing comments.
Do not use @" and "@. The string between will be parsed and variables will be replaced.
I know that you can simply use the uncomment function from a decent code editor. But often, notepad is all you have.
PS: The @' '@ construct is also very useful, if you want to embed other things like XML-code in you script. Here is a small example -
$xml=[xml] @'
<root>
<child>value</child>
</root>
'@
$xml.root.child
2 comments:
Thanks very much for this.
good tip! cheers.
Post a Comment