Hi @oemScript-8271 ,
this is working here:
# This is working in PowerShell 5.1.19041.868
$url = "https://www.hkex.com.hk/eng/stat/dmstat/dayrpt/dqe210401.zip"
$file = "Sample.zip"
Invoke-WebRequest $url -OutFile $file # Download file
# Verify file
If ((Get-Item $file).length -gt 5kb) {
Write-Output "Filesize of $file is greater than 5kb"
}
else {Write-Output "There was an error downloading $file"}
Not sure if you posted the full script. The Catch
in your script without a Try
doesn't make sense or better should not work at all.
https://learn.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-7.1
Break
will break out loops like foreach
, for
, while
, do
, switch
or trap
.
https://learn.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_break?view=powershell-7.1
I would recommend using Return
to terminate a PowerShell script.
https://learn.microsoft.com/de-de/powershell/module/microsoft.powershell.core/about/about_return?view=powershell-7.1
----------
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Andreas Baumgarten