Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell调用Webrequest/提供密码并跳过promt_Powershell_Credentials_Powershell 4.0 - Fatal编程技术网

PowerShell调用Webrequest/提供密码并跳过promt

PowerShell调用Webrequest/提供密码并跳过promt,powershell,credentials,powershell-4.0,Powershell,Credentials,Powershell 4.0,我制作了一个脚本来访问一个需要身份验证的API。如果我在提示符中输入凭据(email+pw),则此选项有效: $cred = Get-Credential $web = Invoke-WebRequest -Uri $srcURI -Credential $cred 但这不允许我自动执行此设置,因为总是会出现提示,询问用户名/PW 我尝试了几种不同的方法,但似乎都不起作用: 对我来说,最符合逻辑的是: $username="user" $password="password1" $

我制作了一个脚本来访问一个需要身份验证的API。如果我在提示符中输入凭据(email+pw),则此选项有效:

$cred = Get-Credential 
$web = Invoke-WebRequest -Uri $srcURI -Credential $cred
但这不允许我自动执行此设置,因为总是会出现提示,询问用户名/PW

我尝试了几种不同的方法,但似乎都不起作用:

对我来说,最符合逻辑的是:

 $username="user" 
 $password="password1"

 $PScredOBJ = New-Object -TypeName System.Management.Automation.PSCredential($username,$password) 
 $cred2 = Get-Credential -Credential $PScredOBJ
结果:仍然显示一个空提示

有人知道怎么处理吗


Thx

这已经在很多地方被讨论过了,谷歌搜索会给出答案。第一个是我用“自动ps凭证”作为搜索词找到的。重申:

$password = "password" | ConvertTo-SecureString  -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential "username",$password