首页 > 解决方案 > Powershell 版本 2 配置系统初始化失败

问题描述

我正在使用 PowerShell 创建一个脚本来向端点发出 http 请求。我知道从 PowerShell 版本 3 开始,我可以使用Invoke-RestMethodor Invoke-WebRequest,但脚本需要与 PowerShell 版本 2 兼容。由于我搜索并阅读了许多论坛,最常见的解决方案是使用 .Net 类System.Net.WebRequest。我正在执行以下几行:

$Uri = "https://url"
$Web = [System.Net.WebRequest]::Create($Uri)

我面临以下错误:

Create : Exception calling "Create" with "1" argument(s): "Configuration system failed to initialize"
At line:1 char:32
+ [System.Net.WebRequest]::Create <<<< ($Uri)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

你能帮忙解决一下可能导致这个问题的原因吗?

标签: powershellpowershell-2.0

解决方案


推荐阅读