我正在尝试在SQL Server作业中设置以下Powershell脚本。在powershell中运行脚本时没有问题,但是从SQL Server作业代理运行时,它将无法完成。它似乎在Invoke-WebRequest上运行在$ wr上。扔出去看看是否有人有解决方案。
[Void][Reflection.Assembly]::LoadWithPartialName("System.Web");
$dlUrl = 'PathtodownloadFile';
$fileName = [System.Web.HttpUtility]::UrlDecode((Split-Path -Path $dlUrl -Leaf));
$dlPath = 'Path{0}'-f $fileName;
$username = "username";
$password = "password";
$wr = Invoke-WebRequest 'LoginPageUrl' -SessionVariable ipc;
$form = $wr.Forms[0];
$form.Fields["username"] = $username; $form.Fields["password"] = $password;
$wr = Invoke-WebRequest -Uri ("PageURL" + $form.Action) -WebSession $ipc -Method POST -Body $form.Fields;
Invoke-WebRequest -WebSession $ipc -Uri $dlUrl -OutFile $dlPath;