Hi, i've created below powershell script which queries the Rubrik API. When I run the script manually in ISE, it all works as expected. But when the script is executed by de SCOM agent, it fails on creating a session with Rubrik ($sessionResponse - last line in script). The returned error is: The underlying connection was closed: An unexpected error occurred on a send.
I've found on multiple sites that TLS1.2 should be enabled in the script, and self-signed certificates should be ignored.
I've implemented them both, but still the issue remains.
# Set protocol and ignore certificate issues
$source = @"
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;
}
}
"@
# Ignore unsigned certificates
Add-Type -TypeDefinition $source
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
# Enable TLS 1.2
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
# Building Rubrik API string
$baseURL = "https://" + $ipaddress + "/api/v1/"
$sessionURL = $baseURL + "session"
$queryURL = $baseURL + "host"
$type = "application/json"
# Create a session
$sessionHeader = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($queryUsr+":"+$queryPwd))}
# Try authenticating with Rubrik API
$sessionResponse = Invoke-RestMethod -Method POST -Uri $sessionURL -Headers $sessionHeader -ContentType $type
Any ideas what the issue could be?