Test Exchange Online Connectivity
6 min
Appendix A: Test Script for Exchange GUID
C# script to test Exchange Online connectivity and retrieve the Exchange GUID:
//@import System.Management.Automation;
using System;
using Innovation.Activate;
using Innovation.Activate.Resources;
using System.Management.Automation;
class Script : ScriptBase
{
public void main()
{
string upn = "[email protected]";
Guid guid = GetExchangeOnlineGuid(upn,true);
Trace.WriteLine($"{guid}");
}
public Guid GetExchangeOnlineGuid(string upn, Boolean returnError)
{
ExchangeResourceOnline eol = Evaluator.GetObject("=//Resources/Exchange Servers/Office365") as ExchangeResourceOnline;
try
{
foreach (PSObject o in eol.Exec("Get-Mailbox", "Identity", upn))
{
Guid guid = (Guid)o.Properties["ExchangeGUID"].Value;
return guid;
}
}
catch (Exception ex)
{
if (returnError)
throw new Exception($"Error retrieving ExchangeGUID for {upn}", ex);
}
return Guid.Empty;
}
}
Appendix B: Orchestrator Certificate Test Task
Activate task for testing certificate availability in Orchestrator.
<Innovation.Activate >
<Task Name="Test Certificate Available" Description="" Status="A" Version="1">
<parameter Name="Arguments" Description="Task Arguments for the Task" Type="Task Arguments" Flags="Required" Version="2" Owner="9cea3147-e9ba-49db-a1b3-867ee9beff14" OwnerPriority="100"><![CDATA[<?xml version="1.0" encoding="utf-8"?><arguments summary="Test Certificate Available"></arguments>]]></parameter>
<parameter Name="Script" Description="" Type="Script" Flags="None" Version="10" Owner="9cea3147-e9ba-49db-a1b3-867ee9beff14"><![CDATA[//@import System.Security.Cryptography;
using System;
using Innovation.Activate;
using System.Security.Cryptography.X509Certificates;
class Script : ScriptBase
{
public void main()
{
// Get certificate thumbprint from Exchange server configuration
string thumbprint = Evaluator.GetString("=//Resources/Exchange Servers/Office365/PSCertificate");
if (String.IsNullOrEmpty(thumbprint))
{
LogError("Thumbprint has not been configured in =//Resources/Exchange Servers/Office365/PSCertificate");
return;
}
// Test in Current User Personal store (most common)
bool foundInCurrentUser = TestCertificate(thumbprint, StoreLocation.CurrentUser, StoreName.My);
// Test in Local Machine Personal store
bool foundInLocalMachine = TestCertificate(thumbprint, StoreLocation.LocalMachine, StoreName.My);
// Display results
LogAudit($"Certificate Search Results for thumbprint: {thumbprint}");
LogAudit($"Found in Current User store: {foundInCurrentUser}");
LogAudit($"Found in Local Machine store: {foundInLocalMachine}");
if (foundInCurrentUser || foundInLocalMachine)
{
LogAudit("Certificate found and accessible");
}
else
{
LogError("Certificate not found in common locations");
}
}
public bool TestCertificate(string thumbprint, StoreLocation location, StoreName storeName)
{
try
{
using (X509Store store = new X509Store(storeName, location))
{
store.Open(OpenFlags.ReadOnly);
// Remove any spaces or formatting from thumbprint
string cleanThumbprint = thumbprint.Replace(" ", "").ToUpper();
X509Certificate2Collection certificates = store.Certificates.Find(
X509FindType.FindByThumbprint,
cleanThumbprint,
false); // false = include invalid certificates
if (certificates.Count > 0)
{
X509Certificate2 cert = certificates[0];
LogAudit($"Found certificate in {location}/{storeName}:");
LogAudit($" Subject: {cert.Subject}");
LogAudit($" Issuer: {cert.Issuer}");
LogAudit($" Valid from: {cert.NotBefore}");
LogAudit($" Valid to: {cert.NotAfter}");
LogAudit($" Has Private Key: {cert.HasPrivateKey}");
return true;
}
return false;
}
}
catch (Exception ex)
{
LogAudit($"Error accessing {location}/{storeName}: {ex.Message}");
return false;
}
}
}]]></parameter>
<parameter Name="Web.Wizard" Description="Options for the Web site" Type="Xml" Flags="Required" Version="3" Owner="9cea3147-e9ba-49db-a1b3-867ee9beff14"><![CDATA[<?xml version="1.0" encoding="utf-8"?><form><wizard startPage="Common/GenericConfirm" title="#TODO: Menu Item" icon2="images/group.gif"><page name="Common/GenericConfirm"><title>Test Certificate Available</title><logo>../images/big_group.gif</logo><message><![CDATA[<P>This task will confirm that the certificate for Exchange Online authentication is available to Orchestrator.</P>] ]></message></page></wizard><view></view></form>]]></parameter>
<parameter Name="Workflow" Description="" Type="Workflow" Flags="None" Version="1" Owner="9cea3147-e9ba-49db-a1b3-867ee9beff14"><![CDATA[<?xml version="1.0" encoding="utf-16"?><workflow><execute script="Script" /></workflow>]]></parameter>
</Task>
</Innovation.Activate>
Appendix C: Certificate Availability Test - PowerShell
$thumbprint = "YOUR_CERT_THUMBPRINT"
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "LocalMachine")
$store.Open("ReadOnly")
$cert = $store.Certificates | Where-Object { $_.Thumbprint -eq $thumbprint }
if ($cert) {
Write-Output "Certificate found: $($cert.Subject)"
} else {
Write-Output "Certificate not found in LocalMachine\My store"
}
$store.Close()
Appendix D: Certificate Availability Test - C#
//@import System.Security.Cryptography;
using Innovation.Activate;
using System;
using System.Security.Cryptography.X509Certificates;
class Script : ScriptBase
{
public void main()
{
string thumbprint = "YOUR_CERT_THUMBPRINT"; // Replace with actual thumbprint
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
try
{
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = store.Certificates.Find(
X509FindType.FindByThumbprint,
thumbprint,
validOnly: false
);
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0];
Trace.WriteLine($"Certificate found: {cert.Subject}, {cert.HasPrivateKey}");
}
else
{
Trace.WriteLine("Certificate not found in LocalMachine\\My store.");
}
}
finally
{
store.Close();
}
}
}