{"record":{"id":"b59bc08ea366937b","repo":"peass-ng/PEASS-ng","slug":"under-windows-8-and-later-emailaction-objects-are","errorCode":null,"errorMessage":"Under Windows 8 and later, EmailAction objects are converted to PowerShell. This action contains headers that are not supported.","messagePattern":"Under Windows 8 and later, EmailAction objects are converted to PowerShell\\. This action contains headers that are not supported\\.","errorType":"exception","errorClass":"System.InvalidOperationException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs","lineNumber":660,"sourceCode":"                    sb.AppendFormat(\" -Cc {0}\", ToPS(Cc));\n                if (!string.IsNullOrEmpty(Bcc))\n                    sb.AppendFormat(\" -Bcc {0}\", ToPS(Bcc));\n                if (bodyIsHtml)\n                    sb.Append(\" -BodyAsHtml\");\n                if (!string.IsNullOrEmpty(Body))\n                    sb.AppendFormat(\" -Body '{0}'\", ToUTF8(Prep(Body)));\n                if (Attachments != null && Attachments.Length > 0)\n                    sb.AppendFormat(\" -Attachments {0}\", ToPS(Array.ConvertAll(Attachments, o => Prep(o.ToString()))));\n                var hdr = new List<string>(HeaderFields.Names);\n                if (hdr.Contains(ImportanceHeader))\n                {\n                    var p = Priority;\n                    if (p != System.Net.Mail.MailPriority.Normal)\n                        sb.Append($\" -Priority {p}\");\n                    hdr.Remove(ImportanceHeader);\n                }\n                if (hdr.Count > 0)\n                    throw new InvalidOperationException(\"Under Windows 8 and later, EmailAction objects are converted to PowerShell. This action contains headers that are not supported.\");\n                sb.Append(\"; \");\n                return sb.ToString();\n\n                /*var msg = new System.Net.Mail.MailMessage(this.From, this.To, this.Subject, this.Body);\n                if (!string.IsNullOrEmpty(this.Bcc))\n                    msg.Bcc.Add(this.Bcc);\n                if (!string.IsNullOrEmpty(this.Cc))\n                    msg.CC.Add(this.Cc);\n                if (!string.IsNullOrEmpty(this.ReplyTo))\n                    msg.ReplyTo = new System.Net.Mail.MailAddress(this.ReplyTo);\n                if (this.Attachments != null && this.Attachments.Length > 0)\n                    foreach (string s in this.Attachments)\n                        msg.Attachments.Add(new System.Net.Mail.Attachment(s));\n                if (this.nvc != null)\n                    foreach (var ha in this.HeaderFields)\n                        msg.Headers.Add(ha.Name, ha.Value);\n                var client = new System.Net.Mail.SmtpClient(this.Server);\n                client.Send(msg);*/","sourceCodeStart":642,"sourceCodeEnd":678,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/Action.cs#L642-L678","documentation":"Under Windows 8+, the library converts EmailAction output to a PowerShell script (since native email actions are deprecated). Custom headers other than the recognized Importance header cannot be represented in that conversion, so if unsupported headers remain the library throws InvalidOperationException instead of silently dropping them.","triggerScenarios":"Reading ToString/PowershellAction conversion of an EmailAction whose Headers collection contains entries other than the standard headers (and ImportanceHeader) — typically after loading a V1 task XML that specified custom mail headers.","commonSituations":"Migrating Windows 7 era scheduled tasks with custom email headers to Windows 8/10/11; importing third-party task definitions that set X- custom headers; user-added headers expecting them to be sent.","solutions":["Remove unsupported custom headers from the EmailAction's Headers collection before conversion/registration","Keep only supported headers (e.g. Importance) and move custom header needs into the email body or the PowerShell script itself","Replace the EmailAction with an explicit PowerShell action (Send-MailMessage / .NET SmtpClient) that supports arbitrary headers","Catch InvalidOperationException during conversion and warn that the action cannot be represented on Windows 8+"],"exampleFix":"// before\nemailAction.Headers.Add(\"X-Custom-Trace\", \"abc123\");\nvar ps = emailAction.ToString(); // throws on Win8+\n// after\n// X-Custom-Trace cannot be represented; embed it in the body or use a PowerShell action\nemailAction.Body = \"Trace: abc123\";\nvar ps = emailAction.ToString();","handlingStrategy":"try-catch","validationCode":"static bool HasUnsupportedHeaders(EmailAction a) =>\n    a.Headers.Keys.Cast<string>().Any(h =>\n        h != \"Importance\" && h.StartsWith(\"X-\", StringComparison.OrdinalIgnoreCase));","typeGuard":null,"tryCatchPattern":"try { var ps = emailAction.ToString(); }\ncatch (InvalidOperationException)\n{\n    log.Warn(\"Email action has headers unsupported by PowerShell conversion (Win8+); replacing with explicit PowerShell action.\");\n}","preventionTips":["Avoid custom mail headers in EmailAction; use body text or a PowerShell action instead","On Windows 8+, prefer Send-MailMessage/SmtpClient actions for full header control","Test task XML imports from legacy systems for header content before conversion","Keep only supported headers (e.g. Importance) in EmailAction"],"tags":["csharp","taskscheduler","email","powershell-conversion","windows-version"],"backgroundTag":"email-action-header-unsupported","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}