Attempting to create a new user using Powershell to a server that does not have trusted certificate.
New to Powershell and Zabbix API - please advise
$zabbixLoginUrl = "https://urzabbixserver/api_jsonrpc.php?"
$userName = "urid"
$userPwd = "urpasssword"
$params =
@{
"jsonrpc" = "2.0"
"method" = "user.create"
"params" = @{
"interfaces" = @{
"alias"="testuser"
"name" = "Craig"
"surname" = "Test"
"type" = "1"
"autologin"="0"
"autologout"="600"
"lang"="en_gb"
"refresh"="90"
}
"auth"="038e1d7b1735c6a5436ee9eae095879e"
"id"= "3"
}
} | ConvertTo-Json -Depth 20
{
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
$loginPostData = @{name=$userName;password=$userPwd;enter="Enter"}
$login = Invoke-RestMethod -Uri $zabbixLoginUrl -Method Post -Body $loginPostData -SessionVariable sessionZabbix -Verbose
}
Invoke-RestMethod -Uri $zabbixLoginUrl -Method post -Body $params
New to Powershell and Zabbix API - please advise
$zabbixLoginUrl = "https://urzabbixserver/api_jsonrpc.php?"
$userName = "urid"
$userPwd = "urpasssword"
$params =
@{
"jsonrpc" = "2.0"
"method" = "user.create"
"params" = @{
"interfaces" = @{
"alias"="testuser"
"name" = "Craig"
"surname" = "Test"
"type" = "1"
"autologin"="0"
"autologout"="600"
"lang"="en_gb"
"refresh"="90"
}
"auth"="038e1d7b1735c6a5436ee9eae095879e"
"id"= "3"
}
} | ConvertTo-Json -Depth 20
{
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
$loginPostData = @{name=$userName;password=$userPwd;enter="Enter"}
$login = Invoke-RestMethod -Uri $zabbixLoginUrl -Method Post -Body $loginPostData -SessionVariable sessionZabbix -Verbose
}
Invoke-RestMethod -Uri $zabbixLoginUrl -Method post -Body $params