Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Email Notification Script is Not Working in Windows Server 2012..

$
0
0

Dears

I have Server 2012 and I wants to make new task seclude for email notification, while any user is login to the server the server will send notification email about user name and IP address for the user, I have script it is working fine in windows 2008 and it is xml file, but the script is not working in 2012 because in task schedule in windows 2008 there is an option called send email but in windows 2012 this option is deprecated, I’m using start program to run the script in PowerShell instead of send email and I configured as an  end-MailMessage-Fromusernamem@domianname.com-Subject"Email Notification"-Tousername@domainName.com-SmtpServermail.domainName.com

But when I use this PowerShell I only receive email notification without any name and IP address, kindly I need your support and help, I’m using below script.

 

<?xml version="1.0" encoding="UTF-16"?>
< Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-11-27T11:16:32.3962177</Date>
    <Author>Company Name\User Name</Author>
    <Description>RDP Login V1</Description>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Security"&gt;&lt;Select Path="Security"&gt;*[System[(EventID=4624)]] and *[EventData[Data[@Name='LogonType'] and (Data=10)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
      <ValueQueries>
        <Value name="IpAddress">Event/EventData/Data[@Name="IpAddress"]</Value>
        <Value name="TargetUserName">Event/EventData/Data[@Name="TargetUserName"]</Value>
      </ValueQueries>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>Company Name\User Name</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</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">
    <SendEmail>
      <Server>Name of the Server.com</Server>
      <Subject>RDP Login V1</Subject>
      <To>Sender Name</To>
      <From>Any Email.com</From>
      <Body>Login Alert on ServerName IP : $(IpAddress)  User: $(TargetUserName). Please take necessary action</Body>
      <HeaderFields />
    </SendEmail>
  </Actions>
< /Task>


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>