Adding user account name to subject line in account lockout powershell script

using the following script to generate account lock out events but can't seem to find a way to include the user account name in the subject line.  any help would be appreciated

$Report= "c:\scripts\lockedout.html"

<title>Account locked out Report</title>

$Account_Name = @{n='Account name';e={$_.ReplacementStrings[-1]}}
$Account_domain = @{n='Account Domain';e={$_.ReplacementStrings[-2]}}
$Caller_Computer_Name = @{n='Caller Computer Name';e={$_.ReplacementStrings[-1]}}

$event= Get-EventLog -LogName Security -InstanceId 4740 -Newest 1 |
   Select TimeGenerated,ReplacementStrings,"Account name","Account Domain","Caller Computer Name" |
   % {
     New-Object PSObject -Property @{
      "Account name" = $_.ReplacementStrings[-7]
      "Account Domain" = $_.ReplacementStrings[5]
      "Caller Computer Name" = $_.ReplacementStrings[1]
      Date = $_.TimeGenerated
  $event | ConvertTo-Html -Property "Account name","Account Domain","Caller Computer Name",Date -head $HTML -body  "<H2> User is locked in the Active Directory</H2>"|
       Out-File $Report -Append

$MailBody= Get-Content $Report
$MailSubject= "User Account Locked Out – MY_Domain\"
$SmtpClient = New-Object
$ = ""
$MailMessage = New-Object
$MailMessage.from = ""
$MailMessage.Subject = $MailSubject
$MailMessage.IsBodyHtml = 1
$MailMessage.Body = $MailBody

David KleinAsked:
Who is Participating?
Shaun VermaakConnect With a Mentor Technical Specialist/DeveloperCommented:
This should work
$MailSubject= "User Account $($event."Account Name") Locked Out – MY_Domain\"

Open in new window

Shaun VermaakTechnical Specialist/DeveloperCommented:
Best solution
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.