I have a question regarding behavior I'm observing when using Invoke-WebRequest within a Powershell ScheduledJob. I think this boils down to "What's the difference between a Powershell ScheduleJob and a conventional Task Scheduler job that would prevent an Invoke-WebRequest from executing?" I've been researching this online but haven't found a solution so far.
Note: The script that is being executed by the scheduled job has been tested successfully in the command shell, Powershell ISE, via a Start-Job, and by a "conventional" scheduled job created in Task Scheduler .
The script makes a web request to an Intranet Sharepoint website that returns a string of XML data. When I run it in a Powershell scheduledjob however, the script "hangs" at the Invoke-WebRequest line. I've tried disabling the progress bar by setting $progressPreference = 'silentlyContinue' in case there was some console interaction issue, but that didn't help (and wasn't needed in all the other test scenarios). I've also tried using the System.Net.WebClient instead, which behaves differently in that it doesn't return anything when used in the scheduledjob.
Here's the code for setting up the scheduled job:
$Script = 'D:\ScheduledJobs\TestScript.ps1'
$Cred = Get-Credential -Message 'Enter Password' -UserName 'MyUser'
$Trigger = New-JobTrigger -Daily -At 4am
Register-ScheduledJob -FilePath $Script -Name PSSchedTest -Credential $Cred -Trigger $Trigger
And this is the part of the TestScript that performs the WebRequest
$progressPreference = 'silentlyContinue':
[xml]$xml1 = Invoke-WebRequest -Uri $uri1 -Credential $cred -Method Get
$progressPreference = 'Continue'
Any assistance gratefully accepted.
DAB