Hi i am trying to download a text file using Powershell Invoke-WebRequest method
Invoke-WebRequest http://www.example.org/script.txt -Outfile DL_script.txt
content of script.txt:
cls
@echo off
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
if '%cmdInvoke%'=='1' goto InvokeCmd
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation
but after downloading.. file looks like this (All Code in Single line, no new line) how can i download file in real format so i can run script
cls@echo offECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"ECHO args = "ELEV " >> "%vbsGetPrivileges%"ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"ECHO Next >> "%vbsGetPrivileges%" if '%cmdInvoke%'=='1' goto InvokeCmd ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation
i need a single line command for download script in real format. tried with these methods but same output (everything in single line)
# Method 1:
Invoke-WebRequest $url -OutFile $path_to_file
# Method 2:
(New-Object System.Net.WebClient).DownloadFile($url, $path_to_file)
# Method 3 (requires BITS may not be immediate):
Import-Module BitsTransfer
Start-BitsTransfer -Source $url -Destination $path_to_file