Prerequisites
Steps to reproduce
- Use Invoke-WebRequest to download a largish file from Google Drive, such as this 100Mb test file:
Invoke-WebRequest -Resume -OutFile HundredMegs.txt 'https://drive.usercontent.google.com/download?id=0B1MVW1mFO2zmdGhyaUJESWROQkE&export=download&confirm=t'
- Press Ctrl+C to interrupt the download before it completes.
- Press up arrow to rerun the same command. Note that it successfully resumes where it left off.
- Allow the download to run to completion.
- Check that the file size is indeed 104857602 bytes.
- Rerun the same Invoke-WebRequest -Resume command again.
- Note that it fails with "Invoke-WebRequest: Object reference not set to an instance of an object."
Expected behavior
Nothing is downloaded because file is already downloaded (i.e., size of OutFile matches file size from server.)
Actual behavior
PS> Invoke-WebRequest -Resume 'https://drive.usercontent.google.com/download?id=0B1MVW1mFO2zmdGhyaUJESWROQkE&export=download&confirm=t' -OutFile HundredMegs.txt
Invoke-WebRequest: Object reference not set to an instance of an object.
Error details
PS> Get-Error
Exception :
Type : System.NullReferenceException
TargetSite :
Name : GetResponse
DeclaringType : [Microsoft.PowerShell.Commands.WebRequestPSCmdlet]
MemberType : Method
Module : Microsoft.PowerShell.Commands.Utility.dll
Message : Object reference not set to an instance of an object.
Source : Microsoft.PowerShell.Commands.Utility
HResult : -2147467261
StackTrace :
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(HttpClient client, HttpRequestMessage request, Boolean handleRedirect)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo : NotSpecified: (:) [Invoke-WebRequest], NullReferenceException
FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
InvocationInfo :
MyCommand : Invoke-WebRequest
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 1
Line : Invoke-WebRequest -Resume 'https://drive.usercontent.google.com/download?id=0B1MVW1mFO2zmdGhyaUJESWROQkE&export=download&confirm=t' -OutFile HundredMegs.txt
Statement : Invoke-WebRequest -Resume 'https://drive.usercontent.google.com/download?id=0B1MVW1mFO2zmdGhyaUJESWROQkE&export=download&confirm=t' -OutFile HundredMegs.txt
PositionMessage : At line:1 char:1
+ Invoke-WebRequest -Resume 'https://drive.usercontent.google.com/downl …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Invoke-WebRequest
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Environment data
PS> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Linux Mint 21.3
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Prerequisites
Steps to reproduce
Expected behavior
Nothing is downloaded because file is already downloaded (i.e., size of OutFile matches file size from server.)Actual behavior
Error details
Environment data
Visuals
No response