Skip to content

Instantly share code, notes, and snippets.

@elico
Created March 25, 2022 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elico/9110bc2a7eab12b9e65a1c1b3e4f8c69 to your computer and use it in GitHub Desktop.
Save elico/9110bc2a7eab12b9e65a1c1b3e4f8c69 to your computer and use it in GitHub Desktop.
Run a mikrotik script remotely via rest API
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