The response content cannot be parsed because the Internet Explorer engine is not available, or
Asked Answered
J

11

221

I need to download a channel 9 series using powershell, however the scripts I have tried have errors:

  1. This script

    $url="https://channel9.msdn.com/blogs/OfficeDevPnP/feed/mp4high"
    $rss=invoke-webrequest -uri $url 
    $destination="D:\Videos\OfficePnP"
    [xml]$rss.Content|foreach{ 
      $_.SelectNodes("rss/channel/item/enclosure") 
    }|foreach{ 
        "Checking $($_.url.split("/")[-1]), we will skip it if it already exists in $($destination)"
      if(!(test-path ($destination + $_.url.split("/")[-1]))){ 
        "Downloading: " + $_.url 
        start-bitstransfer $_.url $destination 
      } 
    }
    

    failed with error:

    The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

  2. I also tried this one

    # --- settings ---
    $feedUrl = "https://channel9.msdn.com/blogs/OfficeDevPnP/feed/mp4high"
    $mediaType = "mp4high"
    $overwrite = $false
    $destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "OfficeDevPnP"
    
    # --- locals ---
    $webClient = New-Object System.Net.WebClient
    
    # --- functions ---
    function PromptForInput ($prompt, $default) {
     $selection = read-host "$prompt`r`n(default: $default)"
     if ($selection) {$selection} else {$default}
    }
    
    function DownloadEntries {
     param ([string]$feedUrl) 
     $feed = [xml]$webClient.DownloadString($feedUrl)
    
     $progress = 0
     $pagepercent = 0
     $entries = $feed.rss.channel.item.Length
     $invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
     $feed.rss.channel.item | foreach {
        $url = New-Object System.Uri($_.enclosure.url)
        $name = $_.title
        $extension = [System.IO.Path]::GetExtension($url.Segments[-1])
        $fileName = $name + $extension
    
        $invalidchars | foreach { $filename = $filename.Replace($_, ' ') }
        $saveFileName = join-path $destinationDirectory $fileName
        $tempFilename = $saveFilename + ".tmp"
        $filename
        if ((-not $overwrite) -and (Test-Path -path $saveFileName)) 
        {
            write-progress -activity "$fileName already downloaded" -status "$pagepercent% ($progress / $entries) complete" -percentcomplete $pagepercent
        }
        else 
        {
            write-progress -activity "Downloading $fileName" -status "$pagepercent% ($progress / $entries) complete" -percentcomplete $pagepercent
           $webClient.DownloadFile($url, $tempFilename)
           rename-item $tempFilename $saveFileName
        }
        $pagepercent = [Math]::floor((++$progress)/$entries*100)
      }
    }  
    
    # --- do the actual work ---
    [string]$feedUrl = PromptForInput "Enter feed URL" $feedUrl
    [string]$mediaType = PromptForInput "Enter media type`r`n(options:Wmv,WmvHigh,mp4,mp4high,zune,mp3)" $mediaType
    $feedUrl += $mediaType
    
    [string]$destinationDirectory = PromptForInput "Enter destination directory" $destinationDirectory
    
    # if dest dir doesn't exist, create it
    if (!(Test-Path -path $destinationDirectory)) { New-Item $destinationDirectory -type directory }
    
    DownloadEntries $feedUrl
    

    with too many errors

    http://screencast.com/t/bgGd0s98Uc

Jeb answered 24/6, 2016 at 3:53 Comment(2)
The answer to your problem is IN the error message (use the UseBasicParsing parameter)Singlehandedly
In fairness, it's easy to see the words "Internet Explorer" in an error message and ignore the rest of the message as you fly into a blind rage on why a command line utility has a dependency on IE.Costello
I
385

In your invoke web request just use the parameter -UseBasicParsing

e.g. in your script (line 2) you should use:

$rss = Invoke-WebRequest -Uri $url -UseBasicParsing

According to the documentation, this parameter is necessary on systems where IE isn't installed or configured:

Uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.

Indelicate answered 27/6, 2016 at 12:52 Comment(3)
For future visitors interested in what UseBasicParsing is doing: Uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system. copied from here: learn.microsoft.com/de-de/powershell/module/…Gilgai
I have Internet Explorer installed on this server and it is setup. And it still requires -UseBasicParsing. Not sure why.Deaden
DonRolling it could be different user context where your script is running and then the system finds IE as not configured for that userNiece
D
86

To make it work without modifying your scripts:

I found a solution here: http://wahlnetwork.com/2015/11/17/solving-the-first-launch-configuration-error-with-powershells-invoke-webrequest-cmdlet/

The error is probably coming up because IE has not yet been launched for the first time, bringing up the window below. Launch it and get through that screen, and then the error message will not come up any more. No need to modify any scripts.

ie first launch window

Despond answered 22/9, 2017 at 14:42 Comment(8)
Worked for me without having to update all the scripts from a Server 2008 server to Server 2012 R2 for a bunch of automated processes to use PowerShell. This used a specific account so I indeed had to run through this with that account signed onto the server.Proceeds
While this does get rid of the error, The need for solving the problem through a GUI is not an acceptable answer, given that PowerShell is meant to be used as an automation platform. This answer will not work for all scenarios, for instance, within a PowerShell Remoting Session.Asseverate
Use a Group Policy Object (GPO) to handle the first run wizard: Computer Configuration > Policies > Administrative Templates > Windows Components > Internet Explorer. Set the "Prevent running First Run wizard"" policy to Enabled and pick an option that suits you.Leftwards
i was having this issue on kubectly proxy and this fixed when i use curl. Thanks!Wu
This scenario will also not work if you have your app inside of some sort of auto scaling group as the new instance being spun up will require this daily/weekly/etc. Best to use the -UseBasicParsingLawrenson
This has already been done on our server, but it didn't help. The -UseBasicParsing flag did the trick.Deaden
Where are the official MS docs for this? In my case, usebasicparsing did not do it, but this gui solution worked.Swanner
This worked for me, was about to go try to download IE before I saw your answer.Nightingale
S
37

You can disable need to run Internet Explorer's first launch configuration by running this PowerShell script, it will adjust corresponding registry property:

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 2

After this, WebClient will work without problems

Suchlike answered 19/10, 2019 at 16:55 Comment(2)
Unfortunately this works fine only on GUI versions but not on Windows Server Core.Doble
@Doble okay, I will try to discover solution for Windows Server CoreSuchlike
D
12

In Windows 10, where after Edge is installed by the OS (and IE not used at all -- as many users just prefer Chrome after a fresh Windows install), when trying to run a script from localhost using

curl http://localhost:3000/

the same error message is received -- as the one Luis mentioned, followed by this one:


        + curl http://localhost:3000/
        + ~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotImplement  
        ed: (:) [Invoke-WebRequest], NotSuppor  
      tedException
        + FullyQualifiedErrorId : WebCmdletIED  
       omNotSupportedException,Microsoft.Powe  
       rShell.Commands.InvokeWebRequestComman  
       d 

If you use instead

Invoke-RestMethod  http://localhost:3000/

the code will work as intended.

I did not try to replicate Luis exact code, however it's still a use case that worked for me.

Also, because the question was asked more than 5 years ago and a best answer was chosen, I decided to still let my answer here just for readers that can use it in another scenario, too (for example when running a code in nodejs and opening a second terminal to test it faster instead of opening a new browser instance)

Declan answered 31/10, 2021 at 1:29 Comment(0)
F
10

It is sure because the Invoke-WebRequest command has a dependency on the Internet Explorer assemblies and are invoking it to parse the result as per default behaviour. As Matt suggest, you can simply launch IE and make your selection in the settings prompt which is popping up at first launch. And the error you experience will disappear.

But this is only possible if you run your powershell scripts as the same windows user as whom you launched the IE with. The IE settings are stored under your current windows profile. So if you, like me run your task in a scheduler on a server as the SYSTEM user, this will not work.

So here you will have to change your scripts and add the -UseBasicParsing argument, as ijn this example: $WebResponse = Invoke-WebRequest -Uri $url -TimeoutSec 1800 -ErrorAction:Stop -Method:Post -Headers $headers -UseBasicParsing

Finnougrian answered 19/10, 2017 at 6:40 Comment(0)
C
6

In your invoke web request just use the parameter -UseBasicParsing

e.g. in your script (line 2) you should use:

$rss = Invoke-WebRequest -UseBasicParsing

According to the documentation, this parameter is necessary on systems where IE isn't installed or configured.

Uses the response object for HTML content without Document Object Model (DOM) parsing. This parameter is required when Internet Explorer is not installed on the computers, such as on a Server Core installation of a Windows Server operating system.

Conchology answered 13/8, 2020 at 2:28 Comment(0)
M
5

Windows Server Core (Tested with Windows Server 2022 Core):

Requirements: Windows Server Languages and Optional Features ISO image

First, install the FOD for Windows Core and restart:

Add-WindowsCapability -Online -Name ServerCore.AppCompatibility~~~~0.0.1.0;

shutdown /r /t 0;

Second, install IE 11 by mounting the Windows Server Languages and Optional Features ISO image:

Add-WindowsPackage -Online -PackagePath "D:\LanguagesAndOptionalFeatures\Microsoft-Windows-InternetExplorer-Optional-Package~31bf3856ad364e35~amd64~~.cab";

Use Get-PSDrive to confirm drive letter.

or

Install Microsoft Edge as recommended by Microsoft:

Invoke-WebRequest -UseBasicParsing -Uri "https://c2rsetup.officeapps.live.com/c2r/downloadEdge.aspx?platform=Default&source=EdgeStablePage&Channel=Stable&language=en"  -OutFile "MicrosoftEdgeSetup.exe"

Disable first launch configuration which blocks Invoke-WebRequest from working on PS

Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 2

I needed to get this working since I was tasked with deploying a Windows Server Core VM with the AD Domain Services Roles and use the StarWars PowerShell Module that internally uses Invoke-WebRequest without the -UseBasicParsing when doing it's API/Downloads in it's scripts for Star Wars AD Characters. Hope this helps anyones else.

Marjorymarjy answered 4/6, 2022 at 19:1 Comment(0)
W
3

I have had this issue also, and while -UseBasicParsing will work for some, if you actually need to interact with the dom it wont work. Try using a a group policy to stop the initial configuration window from ever appearing and powershell won't stop you anymore.

Go to Computer Configuration > Policies > Administrative Templates > Windows Components > Internet Explorer and set the parameter Prevent running First Run Wizard to Enabled.

In the choices you can choose "Go directly to home page".

enter image description here

See here https://wahlnetwork.com/2015/11/17/solving-the-first-launch-configuration-error-with-powershells-invoke-webrequest-cmdlet/

Wimmer answered 21/1, 2020 at 18:39 Comment(1)
you should probably include the main point of the link inside the answer, as the link can rot and become unavailable.Odey
G
2

Simply open Internet Explorer, it will show a pop up for settings, click on Use recommended settings, OK and Close it. All good now.

Gunplay answered 17/3, 2022 at 8:10 Comment(0)
M
0

Yet another method to solve: updating registry. In my case I could not alter GPO, and -UseBasicParsing breaks parts of the access to the website. Also I had a service user without log in permissions, so I could not log in as the user and run the GUI.
To fix,

  1. log in as a normal user, run IE setup.
  2. Then export this registry key: HKEY_USERS\S-1-5-21-....\SOFTWARE\Microsoft\Internet Explorer
  3. In the .reg file that is saved, replace the user sid with the service account sid
  4. Import the .reg file

In the file

Massproduce answered 3/3, 2020 at 3:40 Comment(0)
G
0

In my case, I had to simply change the curl command to Invoke-RestMethod and the error was gone.

Gibraltar answered 23/6, 2021 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.