1

I'm trying to download an exe in my .bat file but I can't hide the output with

$progressPreference = 'silentlyContinue'

| Out-Null

and $null 2>&1.

I don't know why none of them worked.

This is the script that I'm using.

powershell "Invoke-WebRequest http://example.com/example.exe -OutFile "%UserProfileDir%\AppData\LocalLow\example_Data\example.exe"

It downloads the exe perfectly but I can't hide the output.

jdlvoer
  • 21
  • 4
  • [1] what output are you talking about? the progress bar? [2] is there a reason to involve Bat/CMD stuff in this process? – Lee_Dailey Feb 01 '20 at 01:01
  • yes. im talking about the progress bar and im doing some other stuff in the bat so i have to use it. this is just a part from it – jdlvoer Feb 01 '20 at 01:10
  • 5
    if you MUST use a bat file, then call a `.ps1` script, not just commands. put the no-progress setting in that script, then send out ONLY what you need from the script. then let the bat/CMD stuff handle the rest. ///// i can't think of any reason to use a Bat file, tho. most anything that a Bat file does can be done from inside PoSh - including calling almost any utility. [*grin*] – Lee_Dailey Feb 01 '20 at 02:38

1 Answers1

2

You can get inspired by this batch file :

@echo off
set URL=https://www.google.tn/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png
set FileName=%~dp0Google_Logo.png
Call :Download %URL% %FileName%
Start "" %FileName% & Exit
::*********************************************************************************
:Download <URL> <FILE>
Powershell.exe -command "(New-Object System.Net.WebClient).DownloadFile('%1','%2')"
exit /b
::*********************************************************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • the OP wanted to use Invoke-WebRequest only, and the aim is to hide the progress bar. – Wasif Feb 01 '20 at 09:23
  • 1
    @WasifHasan, read [What difference is there between WebClient and HTTPWebRequest classes in .NET?](https://stackoverflow.com/questions/4988286/what-difference-is-there-between-webclient-and-httpwebrequest-classes-in-net). `WebClient` appears to be a lower level function used by `HTTPWebRequest`. `Invoke-WebRequest` is a wrapper (a cmdlet). If use of `WebClient` avoids all the higher level progress bar stuff, then I consider it as +1. – michael_heath Feb 01 '20 at 14:06