Hello all, first time post and first time trying to use CertifyTheWeb. Very excited to get started! I’ve created a script to automate renewing the certificate for all RDS roles. The script works well when I run it natively in Powershell, but CertifyTheWeb console throws the following error:
The deployment task failed to complete. Run…: Run…: Running script [C:\SSL_Update_Test.ps1]
Error Running Script: System.ComponentModel.Win32Exception (0x80004005): The specified executable is not a valid application for this OS platform.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at Certify.Providers.DeploymentTasks.Script.RunLocalScript(ILog log, String command, String args, DeploymentTaskConfig settings, Dictionary2 credentials, Int32 timeoutMins, Boolean launchNewProcess) Error: System.InvalidOperationException: No process is associated with this object. at System.Diagnostics.Process.EnsureState(State state) at System.Diagnostics.Process.get_HasExited() at Certify.Providers.DeploymentTasks.Script.RunLocalScript(ILog log, String command, String args, DeploymentTaskConfig settings, Dictionary
2 credentials, Int32 timeoutMins, Boolean launchNewProcess)
Here is my script:
Parameters
$domainName = “redacted.redacted.com”
$rdServices = @(“RDRedirector”, “RDPublishing”, “RDWebAccess”, “RDGateway”)
$connectionBrokerName = “REDACTED.redacted.com”
$log = @() # Initialize log array
Email parameters
$smtpServer = “mail.smtp2go.com” # SMTP2Go SMTP server address
$smtpPort = 587 # Or 2525, 8025, 25, 465 (SSL/TLS) based on your SMTP2Go settings
$smtpFrom = “redacted@redacted.com” # Your email or sender email approved in SMTP2Go
$smtpTo = “redacted@redacted.com” # Recipient email address
$smtpUser = “sslreport” # SMTP2Go username
$smtpPass = “REDACTED” # SMTP2Go password
$smtpPassSecure = ConvertTo-SecureString $smtpPass -AsPlainText -Force
$smtpCredential = New-Object System.Management.Automation.PSCredential ($smtpUser, $smtpPassSecure)
Function to apply certificate to RD Role and log the operation
function Set-RDCertificate {
param (
[Parameter(Mandatory=$true)]
[string]$role,
[Parameter(Mandatory=$true)]
[string]$thumbprint
)
try {
Import-Module RemoteDesktop
# Correct the cmdlet call to use the actual PowerShell cmdlet and parameters
$roleCert = Get-Item -Path Cert:\LocalMachine\My\$thumbprint
Invoke-Command -ScriptBlock { Set-RDCertificate -Role $using:role -ImportPath $using:roleCert.PSPath -Force -ConnectionBroker $using:connectionBrokerName }
$global:log += "Successfully applied certificate to $role"
}
catch {
$global:log += "Error applying certificate to $role"
throw
}
}
Main script
try {
# Import the RemoteDesktop Module
Import-Module RemoteDesktop
Define the issuer you’re interested in
$issuer = “CN=R3, O=Let’s Encrypt, C=US”
Get the latest certificate with the specified issuer for the domain
$cert = Get-ChildItem -Path Cert:\LocalMachine\My\ |
Where-Object { $.Subject -like “CN=$domainName” -and $.Issuer -eq $issuer } |
Sort-Object -Property NotBefore -Descending |
Select-Object -First 1
$thumbprint = $cert.Thumbprint
$log += "Found certificate with thumbprint: $thumbprint"
Apply the certificate to each RD role without confirmation prompts
foreach ($role in $rdServices) {
Set-RDCertificate -role $role -thumbprint $thumbprint -ConnectionBroker $connectionBrokerName -Force
}
# Restart services to apply the new certificates
try {
Restart-Service -Name "Tssdis" -Force
$log += "Successfully restarted the RD Connection Broker service."
}
catch {
$log += "Failed to restart the RD Connection Broker service"
}
try {
Restart-Service -Name "W3SVC" -Force
$log += "Successfully restarted IIS (W3SVC) for RD Web Access."
}
catch {
$log += "Failed to restart IIS (W3SVC) for RD Web Access"
}
try {
Restart-Service -Name "TSGateway" -Force
$log += "Successfully restarted the RD Gateway service."
}
catch {
$log += "Failed to restart the RD Gateway service"
}
# Prepare success message with log details
$successMessage = "SSL certificates have been applied to all RD roles successfully.`n`nDetails:`n" + ($log -join "`n")
Send-MailMessage -From $smtpFrom -To $smtpTo -Subject "RD SSL Certificate Update Success" -Body $successMessage -SmtpServer $smtpServer -Credential $smtpCredential -UseSsl
}
catch {
# Prepare error message with log details
$errorMessage = “An error occurred during RD SSL Certificate Update.n
nError Details:n$_
nnLog Details:
n” + ($log -join “`n”)
Send-MailMessage -From $smtpFrom -To $smtpTo -Subject “RD SSL Certificate Update Failure” -Body $errorMessage -SmtpServer $smtpServer -Credential $smtpCredential -UseSsl
}
I’m guessing I’m missing something relatively simple. Any ideas?
Thanks,
Mike