Variable text is blank in emails when using Scheduled Task to email event log notifications

I am trying to use powershell to email notification when a user account gets locked.  I am running the script from a server 2008 domain controller.
I have tried multiple scripts and I have the same issue every time.  The script works fine when I run it directly from the powershell command line window.
However whenever I try running the exact same scripts from an event-triggered scheduled task, the script runs, however any content that generated from a variable is not added to the email.  It is just left blank and ignored.
I have tried adding lots of permissions including domain administrator group membership to the account  runs the task from and it doesn't include all the expected text unless I run it from the built-in domain administrator account.
The task runs and the email is sent, but the email is missing all the content generated by variables.
How can this be fixed?
Here is an example script.
$AccountLockOutEvent = Get-EventLog -LogName "Security" -InstanceID 4740 -Newest 1
$LockedAccount = $($AccountLockOutEvent.ReplacementStrings[0])
$AccountLockOutEventTime = $AccountLockOutEvent.TimeGenerated
$AccountLockOutEventMessage = $AccountLockOutEvent.Message
$messageParameters = @{ 
Subject = "Account Locked Out: $LockedAccount" 
Body = "Account $LockedAccount was locked out on $AccountLockOutEventTime.`n`nEvent Details:`n`n$AccountLockOutEventMessage"
From = "[email protected]
To = "[email protected]
SmtpServer = "exch2010.domain.local" 
Send-MailMessage @messageParameters
=================================================
Here is an example of task settings.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2015-03-25T21:40:28.8095226</Date>
    <Author>DOMAIN\administrator</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Security"&gt;&lt;Select Path="Security"&gt;*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and EventID=4740]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>DOMAIN\WilliamsD</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>LeastPrivilege</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>powershell.exe</Command>
      <Arguments>-nologo -File "C:\powershell\l2.ps1"</Arguments>
    </Exec>
  </Actions>
</Task>

By variable text I mean everything that it generates by using a variable such as the user's name ($LockedAccount)
and everything else such as $AccountLockOutEventTime and everything else that is generated from
a variable.
Nothing like that appears in the email only hard coded text.
I am not running it remotely.  I am logged directly onto the domain controller and I tried giving
the account that is used to run the task more and more permissions including domain administrator group membership with the same result.
When I run the exact same script on the same domain controller locally via the powershell CLI all of the info appears.
This is the info when the email is generated by running the script directly from the powershell CLI:
================================================
================================================
Account BondJ was locked out on 03/26/2015 20:42:18.
Event Details:
A user account was locked out.
Subject:
                Security ID:                         S-1-5-18
                Account Name:                 DC1$
                Account Domain:                            
DOMAIN
                Logon ID:                            
0x3e7
Account That Was Locked Out:
                Security ID:                         S-1-5-21-3440879815-2193117124-1719501250-1154
                Account Name:                 BondJ
Additional Information:
                Caller Computer Name:                DC1
===================================================
====================================================
Below is the contents of the email when the same script runs via scheduled task trigger using any account I try other than the built-in domain Administrator account.
=======================================================
======================================================
Account  was locked out on .
Event Details:
===================================================
Just mostly blank email body with the info above.  All the important information text is missing from the email.

Similar Messages

  • The problem is with the new operating system  and sending photo via email when used in my iPad.   From photo I selected 3 photos to send via email. I choose the upload key and choose to send by email. Typing text on the email is very slow.

    The problem is with the new operating system  and sending photo via email when used in my iPad.
    From photo I selected 3 photos to send via email. I choose the upload key and choose to send by email. Typing text on the email is very slow. This is solved by saving the email as a draft and opening the email again from mail.
    Can you amend he system to allow emails to be sent from photo as previously.

    Have you tried restarting or resetting your iPad?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after the iPad shuts down, then press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10 seconds). Ignore the "Slide to power off"

  • I can't see PDFs in email when using iPad

    I can't see PDFs in email when using iPad

    Can you be a little more specific in describing the issue?

  • When using the "submit by email" feature can you add 2 emails?

    When using the "submit by email" feature can you add 2 emails?

    Yes. Seperate them with semicolon (;) just like you would in a normal email client.
    Kyle

  • I am having problems sending emails when using apps. I dont receive any emails when I try to send documents such as pdf or pictures. I tried sending it to my other email account but I don't get any email. What is wrong?

    I am having problems sending emails when using apps. I dont receive any emails when I try to send documents such as pdf or pictures. I tried sending it to my other email account but I don't get any email. What is wrong?

    System Preferences > Network > your-connection-medium > (Assist me) > ( Diagnostics )
    This sometimes provides additional helpful information, sometimes not so much.

  • Why cant I send emails, or open folders, from my Outlook email when using ipad. My Outlook is functioning normally when accessed from laptop.

    Why am I unable to send emails or open folders from my Outlook email when using my iPad?  My Outlook is functioning normally when accessed from my laptop.  This problem has been going on for three days now - everything was functioning normally before. I have looked at the standard troubleshooting suggestions provided by Apple, but they do not appear to cover this eventuality.  I should be most grateful for any help.

    Try first to Clear your cache from : Tools > Options > Advanced > Network, Clear Now button.
    if the above is not helpful, [https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles create a new profile] and check it again.
    if you create the new profile see: [https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles#w_recovering-information-from-an-old-profile Recovering information from an old profile]
    thank you

  • Question about using email when using computer at internet cafe

    I am confused about using email when using my computer at an internet cafe.
    Of course - I use the internet cafe's wifi connection/network.
    How does this effect my email?
    what do I have to do to use my email when logged on at an internet cafe?

    zxcvbnm1 wrote:
    I am confused about using email when using my computer at an internet cafe.
    Of course - I use the internet cafe's wifi connection/network.
    How does this effect my email?
    what do I have to do to use my email when logged on at an internet cafe?
    You don't give enough information to do more than discuss the issue in general terms.  
    You should be able to read your email wherever you can get an internet connection.
    To send email, it depends on the email provider you are using.  Gmail and other web based mail should not have any issues.  However, if you are attempting to use an account that uses your ISP's mail servers, you will probably not be able to send mail.  You may want to check with your ISP in that case, to see if they offer webmail.  
    Hope this may have answered your question.

  • When using "search" i find emails already deleted. How can i definitively delete them from iPad?

    When using "search" i find emails already deleted. How can i definitively delete them from iPad?

    Many thanks James, I have deleted emails from Deleted Items folder in Mail but they are still stored in iPad.
    I do not know how can I do to definetively delete them.

  • Overdue Email when using Workflow "Assign a task".

    The new "Assign a task" action in SharePoint 2013 Workflows contains an option (under Email Options) to "Send Task Overdue Email(s)". You can choose the Frequency and Recurrence of the Emails. I have this set for a particular workflow,
    but we aren't getting those Overdue EMAILS. (All the other EMAILS are working and I AM setting a "Due Date" on the task and the Task isn't marked as "Complete"....) I have read several articles on this subject and this
    article was the only one that seems to address this (new) feature. It says to check the "Expiration" Timer Job (to see how often it is scheduled to run). Well, I only have one "Expiration" Timer Job and it is called "Expiration
    Policy". I am pretty sure this isn't the right Job. Can anyone tell me what the name of the Job is that sends these Emails out?
    Also, what is the "best" way to send out daily emails (reminders) for Tasks that haven't been completed? Should I use "Information Management" and kick off a Workflow that sends the email? (Something similar to what
    this post suggests...) Or, should I create a Timer Job? I am certainly not opposed to writing code, but I would like to do this with OOB functionality if possible (and "practical").
    Any help is MUCH appreciated!!!
    Thanks,
    Shayne

    Has anyone "seen" this work? (bump)
    Shayne

  • I am not receiving the verification email when trying to add an email account

    I am not receiving the verification email when trying to add an email account to facetime and iMessage. Is there something else I can do?

    Hi,
    I don't ever remember getting an email when Adding an account.
    Apple seems to verify it some other way (a self test to see if it is valid ? an actual email ?)
    I tried adding an older @mac.com account that is not a valid email (gained when MobileMe was the Apple service and the @Mac.com registration was used for iChat names).
    I then tried  to add a Yahoo one.
    This got past the first part and said an email has been sent.
    As you say this has never arrived.
    ( checked the web Site for Yahoo Mail as well as my Mail App.)
    In each case I also checked the Spam and Junk folders in both places.
    I then tried an iCloud ID.
    (FaceTime seems to treat the Original Apple ID and the iCloud issued email as separate IDs)
    I did not get and email (Although it said it was sent) I did get a Pop up for the FaceTime app asking if I wanted to add an email and a second for the actual email itself.  (It turned out it added an @me.com email also issued by iCloud before the @icloud.com was issued.
    This is much the way iMessages adds emails when you add the emails to  an iPhone, the Mac version gets pop ups.
    I recently had something similar in Messages that might be related.
    In Messages 7 (Mountain Lion) it seemed it could be any Apple ID that was used.
    In Messages 8 it seems this has to be an iCloud linked one.
    The @mac.com one I used above could not be added to iMessages either when I tried it about two months ago.
    It might be one I have removed the creating/Recovery email so that i could create another Apple ID.
    The name continues to work in Messages as an AIM valid screen name but I could not add it as the iMessages account and got sent to iCloud to "register" it but ran into problems that I have not sorted out yet.
    EDIT.
    Checked the Apple ID site and the @mac.com email I used has no linked Alternative/recovery email.
    8:29 pm      Sunday; March 9, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    Message was edited by: Ralph Johns (UK)

  • I try to find something on my iPad, many results are emails, when I push on an email I can't see the email, because I get ever the first email,or the previous selected email in my inbox. How can I see the email selected?

    I try to find something on my iPad, many results are emails, when I push on an email I can't see the email, because I get ever the first email,or the previous selected email in my inbox. How can I see the email selected?

    Is your Yahoo account set up as POP3 or IMAP?

  • When using tethered capture I often get this notification "The metadata for this photo has been changed by both Lightroom and another application". This slows or stalls the loading of incoming photos. How do I find out which other application is changing

    When using tethered capture I often get this notification "The metadata for this photo has been changed by both Lightroom and another application". This slows or stalls the loading of incoming photos. How do I find out which other application is changing the metadata and stop it?

    Thanks Sean,
    I've had a look at the TC settings dialog and tried to keep it as simple as possible. I also had a copy of LR 4 on the hard drive so have trashed that also incase of any conflicts. LR seems to be running ok now but as said it's an intermittent problem.
    I also have a copy of Capture One on the hard drive so am going to uninstall that also in case it is trying to launch.

  • Exception Thrown When a Scheduled Task Runs for Many Hours

    In the Oracle documentation here (http://download.oracle.com/docs/cd/E10391_01/doc.910/e10367/toc.htm#CACGBDAD) it states that the below exception can get thrown when a scheduled task runs for many hours (on OAS) and can be ignored:
    Primary Server went down going to get a fresh object elsewhere in the cluster.
    com.evermind.server.rmi.RMIConnectionException: LRU connection
    Just want to find out from other users that get this error (If there is any), have you found the scheduled task actually completes, then the error is thrown or what?
    I just don't feel comfortable that one of our tasks is completing properly due to this exception occuring and causing the task to stop midway through processing...

    Hi,
    I've had trouble with scheduling PowerShell scripts in the past as well. You can try running your script in the SYSTEM context by launching a cmd prompt this way, just to verify that the issue isn't related to the account itself:
    http://myitforum.com/cs2/blogs/jmarcum/archive/2010/08/25/150872.aspx
    This method does require PSExec, there's a link to the tool in the post if you don't already have it on hand.
    You can also start PowerShell as SYSTEM and play around if you need to:
    http://blogs.technet.com/b/ben_parker/archive/2010/10/28/how-do-i-run-powershell-exe-command-prompt-as-the-localsystem-account-on-windows-7.aspx?Redirected=true
    Not the best answer, but hopefully it helps shed a little light on the issue.
    Good luck.
    Don't retire TechNet! -
    (Don't give up yet - 12,575+ strong and growing)

  • I need to be able to copy text of a Gmail email I have sent and paste it in a new email when using firefox as my browser

    hi everyone
    I recently upgraded to the new firefox version. When using the previous version. i would copy text in emails I had sent and paste it into new emails. It saved me much time>
    I am totally unable to do this with the newer version of the browser. There is no edit function on the tool bar that allows me to copy and paste.
    any suggestions as to how I can cut and paste or save documents to use over again?
    thanks

    Hi, I had the same issue. My solution was to take the freeware-tool clickto.
    So I'm now able to take any text, copy it and past it via clickto into a new mail.
    [http://www.clicktoapp.com Clickto ]expands your copy-paste feature by showing you some "satellites" after doing the copy action. These "satellites" now will give you some opportunities to paste your copied content, for example a picture to facebook or a text to a new mail on gmail with just 1 single click.

  • Line breaks in emails when using Gmail

    *The problem arises because the iPhone uses "Plain Text" to send emails.*
    *When using gmail, gmail automatically inserts line breaks in "Plain Text" emails every 78 characters, the reason why you see the breaks when unexpected.*
    *See: http://www.google.com/support/forum/p/gmail/thread?id=4d1cecc1aab102ef&hl=en*
    *To fix this problem:*
    *1. Apple can allow us to send mail with Rich Text support from iOS devices OR*
    *2. Google has to change the line breaks setting so that Plain text flows (and isn't broken) <-- this option is probably more realistic*
    *I have tried from a hotmail account, sending email as plain text doesn't have line breaks imposed like the gmail account, but rather "flows".*
    *If you want gmail to add a setting to disable line breaks in plain text emails:*
    *Suggest the feature here:*
    *http://mail.google.com/support/bin/static.py?page=suggestions.cs*
    *I chose these categories:*
    *- I have another idea*
    *- Sending and receiving*
    *- - - Composing and delivery*
    *- - - - Sending options*
    *-For comments: Configure or disable plain text wrap length.*

    I am having the same problem with an IMAP/SMTP account. It was a GMail account, I switched it to using the GMail auto setup and haven't had any issues.
    But under the standard IMAP/SMTP setting almost 1/3 of all messages were showing no content.
    Though I don't recall exactly - I think most of them were sent while I was on 3G, and it otherwise works fine on WiFi.

Maybe you are looking for

  • Breakdown of total percentage in matrix

    Hi I am amending a report that wasn't created by me. I have a matrix table that looks like this (month is the column group and code is the data value Columns Month Code(Sum(field.value)),Sum(Field2.value)) This brings back the following Mar  Apr     

  • XDMCP non reachable

    Hello people, I installed Virtualbox on my Ubuntu host and I installed Arch in my guest machine. The network in the guest IS working: during installation it downloaded all the packages; I can even ping it from the host. I'd say the network is working

  • How to install windows without destroying any existing data?

    I would like to install windows on my macbook 10.5.8, however i dont want to lose any data. And i am thinking if i used boot camp or something similiar it may be destructive while resizing my osx partition. I am also thinking of a virtualization prog

  • Any BAPI or Function module upload data into /LOT/LEOMM01

    Hi ,   Could you tell me please if there is any BAPI or Function module to upload LEO material Property group data (/LOT/LEOMM01) Thanks & Regards RK null

  • XGL causes corrupted images

    I'm working on trying to get XGL working, and I followed the wiki. However, when i boot up (either method one or two), everything gets corrupted and slanty. Except for the terminal area of a konsole i happened to have open. X sort of runs (slowly, an