PowerShell脚本自行打开浏览器

PowerShell脚本自行打开浏览器,powershell,browser,cmdlet,Powershell,Browser,Cmdlet,下面的代码是一个powerShell脚本,它发送POST请求并获取响应,然后将其存储到$response。当我尝试获取表单值并尝试将其存储到$wa时,它会自动打开浏览器 $destination="https://adfs.somedomain.com/adfs/ls/"; $response = ''; $username = 'some username'; $password = 'some password'; $AuthMethod = 'FormsAuthentication'; $

下面的代码是一个powerShell脚本,它发送POST请求并获取响应,然后将其存储到
$response
。当我尝试获取表单值并尝试将其存储到
$wa
时,它会自动打开浏览器

$destination="https://adfs.somedomain.com/adfs/ls/";
$response = '';
$username = 'some username';
$password = 'some password';
$AuthMethod = 'FormsAuthentication';
$postParams = @{
    destination="$destination";
    flags='0';
    forcedownlevel='0';
    trusted='0'
    UserName="$($username)";
    Password="$($password)";
    AuthMethod = "$($AuthMethod)";
    isUtf8='1'
}

$url = "$($destination)?wa=wsignin1.0&wtrealm=urn:federation:cas"
$response = Invoke-WebRequest -uri $url -Method POST -body $postParams;
$wa = $response.InputFields.value[0];
如何使脚本不打开浏览器


注意:它发送post请求,将重定向返回到与get请求相同的uri,并使用我试图存储在变量中的某个表单值进行响应。

所以我发现Powershell使用计算机默认浏览器的解析器解析HTML。这就是它打开浏览器的原因。
使用-UseBasicParsing属性可以使用powershell的HTML解析器。事实证明,至少对于上述情况,Powershell的解析器还不够好

仅执行这两行时会打开浏览器吗?我试着快速复制,做了下面的事情,所有的东西都保存在我的Shell中,没有打开浏览器<代码>$response=调用webrequest-uri“http://google.com“-方法GET$wa=$response.InputFields.value[0]我也无法复制,我认为您在这里遗漏了一些内容。您是否尝试使用-UseBasicParsing参数?有三个输入字段。如果不使用-useBasicPassing,我会得到所有三个,但是如果使用-useBasicPassing,我只会得到其中两个。其中一个输入字段丢失!最后,我使用String类的indexOf和substring方法进行手动解析。