问题
Exploring the difference between help
and get-help
I did:
cd Function:
get-content help
- all the input-parameter are defined like:
[string]${Name}
$
=initiate a variable, {}
a hashtable??
Thanks for your help.
回答1:
For the official documentation, see the conceptual about_Variables help topic (invoke it with help about_Variables
), and in particular its "Variable Names that Include Special Characters" section.
Enclosing the name of a variable in {...}
- e.g. ${foo}
- unambiguously delimits the variable name (foo
).
While you can use this notation with any variable reference, doing so is required in the following scenarios:
If the name contains unusual characters, such as
-
or.
(see the linked help topic for the exact set of permissible characters); e.g.:${foo-bar}
${foo.bar}
If the variable reference is embedded in an expandable string (
"..."
), you may need to tell PowerShell where the variable name ends, if the immediately following characters would otherwise be interpreted as part of the variable name; e.g.:"${foo}: bar"
- without the{...}
, PowerShell would interpret$foo:
as an (incomplete) variable name, which fails, becausefoo
is then interpreted as the name of a PS drive in the context of namespace variable notation.- Note: An alternative in this case is to
`
-escape the:
character:"$foo`: bar"
- Note: An alternative in this case is to
"A ${foo}l and his money ..."
- without the{...}
, PowerShell would look for variable$fool
instead.
While in your example (${Name}
) enclosing in {...}
is not necessary, the reason that it is used is that the code was automatically generated as a proxy function that wraps the Get-Help
cmdlet, and this generation mechanism methodically encloses all variables in {...}
.
来源:https://stackoverflow.com/questions/61205427/powershell-the-syntax-of-help-function