Solving UseBasicParsing Errors in PowerShell

 

Solving UseBasicParsing Errors in PowerShell

April 4, 2020

Today I was trying to write some PowerShell scripts against the Okta PowerShell Module and ran into an error that it doesn't look like I was the only one with. The error, abbreviated, was:


C:\> oktaGetUserByID -userName jesper -Verbose

...

[Microsoft.PowerShell.Commands.HttpResponseException].WARNING: Encountered error, returning limited or empty set

VERBOSE: This Page returned: 0, we've seen: 0 results so far VERBOSE: 0 results returned, i predict an empty page coming up, lets skip it 

VERBOSE: We see no or an invalid next link of: FalsePS 


Getting some more details:

C:\> $Error[0..($Error.count)]

Unable to find type [Microsoft.PowerShell.Commands.HttpResponseException]. At C:\<path>1:491 char:38+ ... .WebException], [Microsoft.PowerShell.Commands.HttpResponseException]+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : InvalidOperation: (Microsoft.Power...sponseException:TypeName) [], RuntimeEx    ception    + FullyQualifiedErrorId : TypeNotFound Invoke-WebRequest : 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. At C:\<path> 1:473 char:29+ ... $request2 = Invoke-WebRequest -Uri $uri -Method $method -UserAgent $u ...+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException    + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand


What's going on here is interesting. The Invoke-WebRequest function requires you to have launched Internet Explorer and proceeded past the Internet Explorer first launch experience, because it apparently uses some Internet Explorer component for parsing. To avoid this, the error says that you can include the UseBasicParsing parameter. However, that parameter has been deprecated and no longer works. Furthermore, I'm running Windows 10, and there is no Internet Explorer to launch, so what I do? 


It turns out that you need to tell the OS not to bother with the Internet Explorer first launch experience. Save this to a .reg file and run it, or make this change directly in the registry:


[HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Internet Explorer\Main]

"DisableFirstRunCustomize"=dword:00000001


Once you do that, IE, or whatever is left of it in Windows 10, knows that you don't want to go through the first launch experience, and now your PowerShell command will work.  


It took me some searching to figure this out so I thought if I post it here in context, with more complete error messages, maybe it will help someone else. 

Comments

Popular posts from this blog

U2F, FIDO2, and Hardware Security Keys

The Busy Executive’s Guide to Personal Information Security

Single Sign-On