当前位置: 首页 > 知识库问答 >
问题:

执行power shell脚本时出错

聂溪叠
2023-03-14
Script:
username = "admin"
password = "******"
authInfo = ("{0}:{1}" -f $username,$password)
authInfo = [System.text.Encoding]:: UTF8.GetByteCount($authInfo)
authInfo = [System.Convert]::ToBase64String($authInfo)
headers = @{Accept=("application/json");Contenttype=("appliaction/json");Authorization=("Basic {0}"-f $authInfo)}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::"tls12, tls11, tls"
Invoke-WebRequest -Uri https://njidlsdsapp01/support

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} 

uri = "https://njidlsdsapp01/support"
body = "{'login':'admin','login_pwd':'*****','commands' :['create a new support file']}" 
res = invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body $body
res

Invoke-WebRequest:请求中止:无法创建SSL/TLS安全通道。在C:\users\njujjavarapu\desktop\snapshot.ps1:8 char:1+Invoke-WebRequest-uri https://njidlsdsapp01/support

Name                           Value                                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                                             
Contenttype                    appliaction/json                                                                                                                                                                                                                  
Accept                         application/json                                                                                                                                                                                                                  
Authorization                  Basic Eg==                                                                                                                                                                                                                        

invoke-RestMethod:请求中止:无法创建SSL/TLS安全通道。在C:\users\njujjavarapu\desktop\snapshot.ps1:19 char:8+$res=invoke-RestMethod-uri$uri-headers$headers-method post-bo...指挥

共有1个答案

淳于玺
2023-03-14
  1. Exception setting "SecurityProtocol":
    "Cannot convert null to type "System.Net.SecurityProtocolType"
    due to enumeration values that are not valid.
    Specify one of the following enumeration values and try again.
    The possible enumeration values are "SystemDefault,Ssl3,Tls,Tls11,Tls12"."
    

    使用

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]"tls12, tls11, tls"
    

    或者只是

    [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
    

    我得到以下错误

    There is no Runspace available to run scripts in this thread.
    
    You can provide one in the DefaultRunspace property
    of the System.Management.Automation.Runspaces.Runspace type.
    
    The script block you attempted to invoke was: $true
    
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} 
    
    add-type @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }
    "@
    [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
    

 类似资料:
  • 问题内容: 我正在尝试从Jenkins运行PowerShell脚本,但是它似乎完全忽略了执行策略!通过直接执行powershell.exe或使用PowerShell插件来实现 附加信息: Jenkins作为Windows服务运行(使用本地系统帐户,非交互式)。连接到该服务器并检查执行策略确实是: 但是,在运行Jenkins构建时,情况并非如此。这是在构建步骤中执行的输出: 我还尝试从构建步骤明确设

  • 问题内容: 我一直在网上和Stackoverflow上浏览,但是没有找到这个问题的答案。您将如何从Node.js执行Powershell脚本?该脚本与Node.js实例位于同一服务器上。 问题答案: 您可以仅生成一个子进程“ powershell.exe”,并侦听stdout的命令输出和stderr的错误:

  • 问题内容: 如何从“脚本” 执行PowerShell ps1脚本? 我知道如何在package.json“ scripts”中设置基本脚本。例如,使用以下配置,我可以执行该命令,该命令将向控制台输出“这仅仅是测试”: 但是,我有一个更高级的场景,我想执行一个PowerShell脚本。像这样: 我可以通过scripts对象执行这样的ps1脚本吗?是否需要任何特殊的设置/配置?还有其他限制吗? 问题答

  • 当我试图使用执行PHP脚本时,它不起作用。 在错误日志文件中显示: PHP警告:shell_exec()[function.shell exec]:无法执行'PHP/home/snabsam/public_html/。。。。。 系统 Centos shell_exec与clamscan配合使用 与clamav的功能配合使用 但它没有执行PHP脚本 我检查过的东西: PHP是off 不存在于在php

  • 我是新加入Broadleaf电子商务的,几天前也安装了同样的软件。Maven构建是成功的,但是在启动Startadmin时出错。批处理文件。我尝试过增加堆内存,但没有效果。你们中有人遇到过类似的错误吗? 错误打开zip文件或JAR清单丢失:目标/代理/斯普林-仪器. jar 虚拟机代理库初始化过程中发生错误未能初始化:仪器 虚拟机初始化过程中发生错误太小的初始堆 虚拟机初始化过程中发生错误太小的初

  • 本文向大家介绍Powershell直接脚本时出现无法加载文件因为禁止执行脚本,包括了Powershell直接脚本时出现无法加载文件因为禁止执行脚本的使用技巧和注意事项,需要的朋友参考一下 在Powershell直接脚本时会出现: 无法加载文件 ******.ps1,因为在此系统中禁止执行脚本。有关详细信息,请参阅 "get-help about_signing"。 所在位置 行:1 字符: 17