Created
March 25, 2022 00:10
-
-
Save elico/9110bc2a7eab12b9e65a1c1b3e4f8c69 to your computer and use it in GitHub Desktop.
Run a mikrotik script remotely via rest API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add-type @" | |
using System.Net; | |
using System.Security.Cryptography.X509Certificates; | |
public class TrustAllCertsPolicy : ICertificatePolicy { | |
public bool CheckValidationResult( | |
ServicePoint srvPoint, X509Certificate certificate, | |
WebRequest request, int certificateProblem) { | |
return true; | |
} | |
} | |
"@ | |
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy | |
$user = 'admin' | |
$pass = '1234' | |
$pair = "$($user):$($pass)" | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
$basicAuthValue = "Basic $encodedCreds" | |
$Headers = @{ | |
Authorization = $basicAuthValue | |
} | |
$body = @{ | |
".id" = "switchSimCard" | |
} | |
$routerOSHost = "192.168.88.1" | |
$url = "https://$routerOSHOST/rest/system/script/run" | |
Invoke-WebRequest -Uri $url -Body ($body|ConvertTo-Json) -Headers $Headers -Method POST -ContentType application/json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment