Search notes:

PowerShell: Invoke-WebRequest - Desktop vs Core edition

The PowerShell cmdLet invoke-webRequest behaves differently when executed in PowerShell Desktop (aka 5.1?) or PowerShell Core (aka 7?).
The following simple script tries to demonstrate the most important differences:
set-strictMode -version 3

function check-eq {
   param (
      [string] $value,
      [string] $expectedDesktopValue,
      [string] $expectedCoreValue
   )

   if ($psVersionTable.psEdition -eq 'Desktop') {
      if ($value -ne $expectedDesktopValue) {
         write-host "Expected Desktop value was $expectedDesktopValue, but I had $value"
      }

   }
   elseif ($psVersionTable.psEdition -eq 'Core') {

      if ($value -ne $expectedCoreValue) {
         write-host "Expected Core value was $expectedCoreValue, but I had $value"
      }

   }

}

$url = 'https://renenyffenegger.ch/'

$response         = invoke-webRequest $url
$baseResponse     = $response.baseResponse

$responseType     =     $response.GetType().FullName
$baseResponseType = $baseResponse.GetType().FullName

check-eq     $responseType  'Microsoft.PowerShell.Commands.HtmlWebResponseObject'   'Microsoft.PowerShell.Commands.BasicHtmlWebResponseObject'
check-eq $baseResponseType  'System.Net.HttpWebResponse'                            'System.Net.Http.HttpResponseMessage'
Github repository about-PowerShell, path: /cmdlets/webRequest/invoke/desktop-vs-core.ps1

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1759612605, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/command-inventory/noun/webRequest/invoke/desktop-vs-core(73): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78