PowerShell, the syntax of help-function

让人想犯罪 __ 提交于 2021-02-08 06:31:33

问题


Exploring the difference between help and get-help I did:

  1. cd Function:
  2. get-content help
  3. 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, because foo 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"
    • "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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!