sync: auto-sync from DESKTOP-0O8A1RL at 2026-05-12 07:04:17

Author: Mike Swanson
Machine: DESKTOP-0O8A1RL
Timestamp: 2026-05-12 07:04:17
This commit is contained in:
2026-05-12 07:04:18 -07:00
parent b1a588d0db
commit e75ddfbc53
3 changed files with 196 additions and 57 deletions

View File

@@ -7,7 +7,7 @@ $nodeExe = 'C:\Program Files\nodejs\node.exe'
New-Item -ItemType Directory -Force -Path $logDir | Out-Null
$stamp = Get-Date -Format 'yyyy-MM-dd_HH-mm-ss'
$log = Join-Path $logDir "pipeline-$stamp.log"
$smtpCred = $null
$graphCreds = $null
function Log([string]$m) {
$line = "[$(Get-Date -Format o)] $m"
@@ -16,17 +16,37 @@ function Log([string]$m) {
}
function SendEmail([string]$Subject, [string]$Body) {
if ($null -eq $smtpCred) { return }
if ($null -eq $graphCreds) { return }
try {
Send-MailMessage `
-From 'sysadmin@dataforth.com' `
-To @('mike@azcomputerguru.com') `
-Subject $Subject `
-Body $Body `
-SmtpServer 'smtp.office365.com' `
-Port 587 `
-UseSsl `
-Credential $smtpCred
# Acquire Graph token
$tokenBody = @{
grant_type = 'client_credentials'
client_id = $graphCreds.clientId
client_secret = $graphCreds.clientSecret
scope = 'https://graph.microsoft.com/.default'
}
$tokenResp = Invoke-RestMethod `
-Method Post `
-Uri "https://login.microsoftonline.com/$($graphCreds.tenantId)/oauth2/v2.0/token" `
-Body $tokenBody
$token = $tokenResp.access_token
# Send mail via Graph
$mailPayload = @{
message = @{
subject = $Subject
body = @{ contentType = 'Text'; content = $Body }
toRecipients = @(@{ emailAddress = @{ address = 'mike@azcomputerguru.com' } })
from = @{ emailAddress = @{ address = 'sysadmin@dataforth.com' } }
}
} | ConvertTo-Json -Depth 10
Invoke-RestMethod `
-Method Post `
-Uri 'https://graph.microsoft.com/v1.0/users/sysadmin@dataforth.com/sendMail' `
-Headers @{ Authorization = "Bearer $token"; 'Content-Type' = 'application/json' } `
-Body $mailPayload | Out-Null
Log "Email sent: $Subject"
} catch {
Log "WARNING: Email send failed: $_"
@@ -44,12 +64,15 @@ try {
$env:CF_CLIENT_SECRET = $creds.CF_CLIENT_SECRET
$env:CF_SCOPE = $creds.CF_SCOPE
if ($creds.SMTP_USER -and $creds.SMTP_PASS) {
$secPass = ConvertTo-SecureString $creds.SMTP_PASS -AsPlainText -Force
$smtpCred = New-Object System.Management.Automation.PSCredential($creds.SMTP_USER, $secPass)
Log "SMTP credentials loaded for $($creds.SMTP_USER)"
if ($creds.GRAPH_TENANT_ID -and $creds.GRAPH_CLIENT_ID -and $creds.GRAPH_CLIENT_SECRET) {
$graphCreds = [PSCustomObject]@{
tenantId = $creds.GRAPH_TENANT_ID
clientId = $creds.GRAPH_CLIENT_ID
clientSecret = $creds.GRAPH_CLIENT_SECRET
}
Log "Graph credentials loaded (app $($creds.GRAPH_CLIENT_ID))"
} else {
Log "WARNING: SMTP_USER/SMTP_PASS not in credentials.json — email notifications disabled"
Log "WARNING: GRAPH_TENANT_ID/CLIENT_ID/CLIENT_SECRET not in credentials.json — email notifications disabled"
}
# [1] DFWDS process
@@ -77,7 +100,7 @@ try {
# [4] Daily summary email
Log '[4] sending daily summary email'
if ($smtpCred) {
if ($graphCreds) {
try {
# Parse totals from most recent upload log; default to zeros if not found
$totals = [PSCustomObject]@{ received=0; created=0; updated=0; unchanged=0; errors=0 }
@@ -109,7 +132,7 @@ Log: $($latestUploadLog.FullName)
Log "WARNING: Summary email failed: $_"
}
} else {
Log ' SMTP not configured — skipping summary email'
Log ' Graph credentials not configured — skipping summary email'
}
Log '=== pipeline end (OK) ==='