为什么 powershell 会抱怨注释行?

Cat*_*ter 4 powershell

我在 powershell 脚本中有以下评论:

\n\n
#ERROR: Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.\n#EXPLANATION: PowerShell calls uses TLS 1.0 for web requests by default. \n#             However, Exchange is expecting a higher level of TLS, so you need to tell PowerShell to use 1.2 instead of the default of TLS 1.0\n\xe2\x80\x8b#SOLUTION(s): \n#             [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n
Run Code Online (Sandbox Code Playgroud)\n\n

当我运行脚本时,我收到此错误:

\n\n
s : The term 's' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the\nspelling of the name, or if a path was included, verify that the path is correct and try again.\nAt ps1:4 char:14\n+ \xc3\xa2\xe2\x82\xac\xe2\x80\xb9#SOLUTION(s):\n+              ~\n    + CategoryInfo          : ObjectNotFound: (s:String) [], CommandNotFoundException\n    + FullyQualifiedErrorId : CommandNotFoundException\n
Run Code Online (Sandbox Code Playgroud)\n\n

为什么要抱怨评论?

\n\n

如果我删除它然后抱怨解决方案本身......

\n

Ril*_*ney 5

您已将其发布在错误日志中:+ \xc3\xa2\xe2\x82\xac\xe2\x80\xb9#SOLUTION(s):

\n\n

#SOLUTION(s): 左侧的代码中的之前有一个空字符,因此它正在将该行读入 powershell。只需删除该行\xe2\x80\x8b#SOLUTION(s):并重新输入即可。

\n\n

要检查将行复制并粘贴到 powershell 控制台中,应按如下所示读出:

\n\n

在此输入图像描述

\n

  • 哇!这到底是怎么可能的……我按了退格键,那里似乎真的有东西!但怎么办?一切都与上面的评论一致......这些空字符是怎么来的? (2认同)