0

sh file that make a server reboot then needed, and I have to convert this command in .batch for windows and in Powershell too I can't find how to pass the variables for user, pass and the instruction not to chech the SSL certificate in the windows version. Can anyone help? thank you

Linux SH file (working)

#!/bin/sh
ip_address=192.168.0.5
username=myuser
password=mypass
wget --no-check-certificate --user=$username --password=$password -qO- https://$ip_address/reboot

Windows Batch file (in progress)

@echo off
set ip_address=192.168.0.5
set username=myuser
set password=mypass
start https://%ip_address%/reboot
rem so far it open the requested URL, but it checks the SSL certificate so it blocks the execution, and i don't know how to pass user and password
1
  • there is no .batch it's .bat
    – barlop
    Jan 22, 2019 at 12:06

1 Answer 1

0

Powershell

Something like this should do.

$user = "user"
$pass = "password"
$secpass = ConvertTo-SecureString $pass -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential($user, $secpass)

Invoke-WebRequest -Uri "https://$ip_address/reboot" -SkipCertificateCheck -Credential $credential

Note that -SkipCertificateCheck is only available in PowerShell 6.0. [1]

BAT

start in batch file starts associated handler on its argument (for URL as in your case it would be default browser)

To achieve your goal you have to install wget for windows (or curl for windows), and use it with the same arguments as in your original shell script.

I think there are no ways to do what you want in cmd/bat files using only standard functionality. However some WMI wizardry can do the trick.

[1] https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6
[2] http://gnuwin32.sourceforge.net/packages/wget.htm
[3] https://curl.haxx.se/windows/

4
  • that would be the best option, but unfortunately I cannot touch the customers computers. That's way I have to convert them into .batch and or .ps
    – Kraugh
    Jan 22, 2019 at 11:24
  • So, your question is not about passing parameters in a batch file, but finding a tool to open an url with authentication, right? BTW, are there any other restrictions? And if you cannot touch the computer, how your powershell script will be run (PS execution is disabled by default, and you need admin privileges to enable it)?
    – trolzen
    Jan 22, 2019 at 11:45
  • if he can run powershell then powershell apparently can (at least to some extent) do the equivalent of wget/curl
    – barlop
    Jan 22, 2019 at 12:07
  • Added ps script. I really think using wget would be much simpler solution than trying to find workaround for standard windows installation limitations. Wget is portable, doesn't need install, so you can put it alongside your script.
    – trolzen
    Jan 22, 2019 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.