首页 > 解决方案 > 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
#*************************************************************************

标签: powershellapiproxycredentials

解决方案


这是我用来登录服务器的服务帐户的特定内容。更改了帐户,并且在两个版本上都可以使用。不知道有什么区别,但我得到了我需要的东西。


推荐阅读