2

So, I am making an "Assistant" that is completely command line based. I recently decided to move from hosting files on One-drive to GitHub. I had made tiny.cc links so it would be easy to change the final url without having to change the batch file itself.

But, as soon as I redirected my tiny.cc urls to my files on GitHub I got errors. I was using powershell -Command Invoke-WebRequest http://tiny.cc/sanchitaiexdown -OutFile C:\Users\%USERNAME%\ai\exdown.exe

And it came with the error could not create SSL/TLS Secure Channel. After a bit of research I found that I had to use this command before it,

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

The issue with this was, it couldn't be run in batch (I want to stay in batch). So I tried BitsAdmin and it failed me as well.

So, is there a way I can make this work in BATCH. I am fine if an external exe is needed, but it can only be command line and no installation needed.

Thanks

4
  • Your shortened url isn’t https, GitHub only supports, secure connections. There isnt a point in declaring you support TLS 1.0+ if your not using a https connection.
    – Ramhound
    Jun 10, 2018 at 22:43
  • I'd actually run [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" and then the Invoke-WebRequest command but you can run both of those via batch using a batch script just fine. Jun 10, 2018 at 22:43
  • @Ramhound The tiny.cc link is http, but the link it goes to is https.
    – user473470
    Jun 10, 2018 at 22:56
  • @PimpJuiceIT I just tried that and I came up with an error. Also, I have tried the orignal commands in powershell and they work, but in batch they dont, and I want to stick with batch.
    – user473470
    Jun 10, 2018 at 22:56

1 Answer 1

1

You can run the PowerShell commands via batch by putting the PowerShell logic into a dynamically created PowerShell script using the echo command, and then the PowerShell script can be executed to run the logic and do whatever you need it to do as in the below example.


Script Example

@ECHO ON

:PowerShell
SET PSScript=%temp%\~tmpDlFile.ps1
IF EXIST "%PSScript%" DEL /Q /F "%PSScript%"
ECHO [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls">>"%PSScript%"
ECHO Invoke-WebRequest "http://tiny.cc/sanchitaiexdown" -OutFile "C:\Users\%USERNAME%\ai\exdown.exe">>"%PSScript%"

SET PowerShellDir=C:\Windows\System32\WindowsPowerShell\v1.0
CD /D "%PowerShellDir%"
Powershell -ExecutionPolicy Bypass -Command "& '%PSScript%'"
EXIT

Further Resources

2
  • Thanks, I just turned @ECHO OFF to give the script a clean look.
    – user473470
    Jun 11, 2018 at 0:22
  • @user473470 That's just a habit of mine where I like to see everything echo'd.... I'm glad it worked for your needs!! Jun 11, 2018 at 0:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .