powershell - Powershell7代理认证
问题描述
我是 PowerShell 新手,我继承了一些代码,这些代码迫使我在我的 Windows Server 2012 上使用 Powershell7 over 5.1,现在我无法获得我的凭据来跨组织的代理进行身份验证。我在想 Powershell7 环境中有一些东西没有安装/不再支持/没有正确配置。下面的代码在 5.1 中有效,但在 7 中,我从我们的代理收到一条消息,说它缺少凭据。任何人都可以阐明该怎么做吗?
#*************************************************************************
# Proxy Credentials
#*************************************************************************
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://proxy.############')
$username ="###################"
$password ="###################"
$securePwd = $password| convertto-securestring -AsPlainText -Force
$Creds=new-object System.Management.Automation.PSCredential ($username,$securePwd)
$Wcl=New-Object System.Net.WebClient
$Wcl.Proxy.Credentials=$Creds
#*************************************************************************
# Authentication Call
#*************************************************************************
$uri = 'https://testapi.com/web/authenticate'
$params = '{"userName": "######",
"password": "########"
}'
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$token =Invoke-Webrequest -Method Post -Uri $uri -body $params -ContentType "application/json" -UseBasicParsing |ConvertFrom-Json | Select AuthenticateResult
write-host $token
#*************************************************************************
解决方案
这是我用来登录服务器的服务帐户的特定内容。更改了帐户,并且在两个版本上都可以使用。不知道有什么区别,但我得到了我需要的东西。
推荐阅读
- docker - 持久卷声明 - 挂载路径
- python-3.x - 用python结合图片
- c++ - 函数的签名是什么意思?
- r - 使用 PLOTLY 包修改绘图
- c++ - 在 DLL 之外使用工厂类是否安全?
- node.js - Sequelize - Postgres - 如何从联结表创建新对象
- java - 如何使用 Gradle 修复“包 com.sun.webkit 不可见”的编译错误?
- javascript - 如何用 jQuery 查找和替换类名的前缀?
- javascript - 使用 Javascript 解码密码编码的字符串
- android - Android将数据保存到firebase数据库