为什么Powershell抱怨注释行?

时间:2019-04-30 21:19:15

标签: powershell

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

#ERROR: Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
#EXPLANATION: PowerShell calls uses TLS 1.0 for web requests by default. 
#             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
​#SOLUTION(s): 
#             [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

运行脚本时出现此错误:

s : The term 's' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At ps1:4 char:14
+ ​#SOLUTION(s):
+              ~
    + CategoryInfo          : ObjectNotFound: (s:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

为什么抱怨评论?

如果我将其删除,则会抱怨SOLUTION本身...

1 个答案:

答案 0 :(得分:3)

您已将其发布在错误日志中:+ ​#SOLUTION(s):

在您的代码中#前面的SOLUTION(s):左边有一个空字符,因此它将行读入powershell。只需删除​#SOLUTION(s):行并重新输入即可。

要检查将行复制并粘贴到powershell控制台中,应读取如下内容:

enter image description here