Fastvue certificate-renewal scheduled-task example

Inspect the recovered PowerShell example for scheduling Fastvue certificate renewal. It requires elevation and a renewal-script path; it is reference text, not an executed or validated task installer.

New-FastvueCertificateRenewalTask

# Scheduled Task Creation Script for Certificate Renewal

# Run this script with elevated permissions to create the scheduled task

param(

[Parameter(Mandatory=$true)]

[string]$Domain,

[Parameter(Mandatory=$false)]

[string]$ScriptPath = "C:\Scripts\Update-FastvueCertificate.ps1",

[Parameter(Mandatory=$false)]

[string]$TaskName = "Fastvue SSL Certificate Renewal",

[Parameter(Mandatory=$false)]

[string]$SiteName = "Default Web Site"

)

# Check if running as Administrator

if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {

Write-Error "This script must be run as Administrator"

exit 1

}

try {

Write-Host "Creating scheduled task for SSL certificate renewal" -ForegroundColor Green

# Create the action

$actionArgs = "-NoProfile -ExecutionPolicy RemoteSigned -Command `"& '$ScriptPath' -Domain '$Domain' -SiteName '$SiteName'`""

$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument $actionArgs

# Create the trigger (daily between 1am and 1:45am)

$trigger = New-ScheduledTaskTrigger -Daily -At 1am -RandomDelay (New-TimeSpan -Minutes 45)

# Create task settings

$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable -RunOnlyIfNetworkAvailable -DontStopOnIdleEnd

# Create principal with highest privileges

$principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest

# Register the task

Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Description "Automated SSL certificate renewal using Posh-ACME with IIS binding updates"

Write-Host "Scheduled task '$TaskName' created successfully" -ForegroundColor Green

Write-Host "Task details:" -ForegroundColor Cyan

Write-Host " - Runs daily between: 1am and 1:45am" -ForegroundColor White

Write-Host " - Domain: $Domain" -ForegroundColor White

Write-Host " - Site: $SiteName" -ForegroundColor White

Write-Host " - Script: $ScriptPath" -ForegroundColor White

Write-Host " - Runs as: SYSTEM with highest privileges" -ForegroundColor White

# Show the created task

Get-ScheduledTask -TaskName $TaskName | Format-Table -AutoSize

Write-Host "You can view logs at: C:\Scripts\Logs\CertRenewal.log" -ForegroundColor Yellow

Write-Host "To test the task manually, run: Start-ScheduledTask -TaskName '$TaskName'" -ForegroundColor Yellow

} catch {

Write-Error "Failed to create scheduled task: (_.Exception.Message)"

exit 1

}