Invoke-WebRequest under the System Account


Invoke-WebRequest is a versatile Powershell CmdLet. However the way it works behind the scene creates sometimes strange behaviors.

As you may aware the HTML parser engine greatly depends on system components and Web Browser such as Internet Explorer.

A consequence of such a “design”, is that even on Windows Server 2016, you may have non-working Powershell scripts when running under accounts whose profile has not been initialized for the underlying system application.

As such, you will often find that a script which works flawlessly under your account doesn’t retrieve anything when launched under a scheduled task. This typically includes tasks running under the System Account.

A work-around is to run once the iexplore.exe binary under the System Account. This could be accomplished using a command such as psexec.exe -sid "%ProgramFiles%\Internet Explorer\iexplore.exe" under the command prompt or ./psexec.exe -sid "$Env:ProgramFiles\Internet Explorer\iexplore.exe" under Powershell.

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.