Created
October 27, 2022 13:45
-
-
Save MayMeow/62d3b53b6052914c7e96e297bf5813cb to your computer and use it in GitHub Desktop.
Execute script over API on Mikrotik router
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 | |
$Body = @{ | |
number = "script-name"; | |
} | |
$user = "user" | |
$password = "pass" | |
$apiEndpoint = "https://mikrotik-IP/rest/system/script/run" # You need to have the www-ssl service set up correctly | |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($user):$($password)")) | |
$Header = @{ | |
Authorization = "Basic $base64AuthInfo" | |
} | |
$Parameters = @{ | |
Header = $Header | |
Method = "POST" | |
Uri = $apiEndpoint | |
ContentType = "application/json" | |
# SkipCertificateCheck = $true | |
Body = ($Body | ConvertTo-Json) | |
} | |
Invoke-RestMethod @Parameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment