我是 PowerShell 新手,我继承了一些代码,这些代码迫使我在 Windows Server 2012 上使用 5.1 以上的 Powershell7,现在我无法获取我的凭据以通过组织的代理进行身份验证。我在想 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
#*************************************************************************
答案 0 :(得分:0)
这是我用来登录服务器的服务帐户的特定内容。更改了帐户,它适用于两个版本。不知道有什么区别,但我得到了我需要的东西。