trigger windows program using get-content -wait


hello guys,

please how can trigger windows program cmd using get-content -wait. monitoring windows program log using get-content -wait, how can run cmd mailer on receipt of new entry file. tried using below no avail.

ps c:\users\administrator> gc c:\snort\log\alert.ids -wait | cmd.exe /c "c:\blat\blat.exe -to xxxx.yyyy@
contoso.com -subject ("ids alert!") -body ("ids alert") -attachi c:\snort\log\alert.ids"

i want logs emailed on receipt of new item.

kind regards , in advance.

when tail file get-content’s wait switch, cmdlet first outputs current content , new, or appended, content cmdlet hijacks current session, can run code background job (psremotingjob). can use output trigger , include body of message, have pipe get-content’s output foreach-object cmdlet or use in foreach loop , try your cmd statement – /c flag – there. since get-content first output current content, need number of lines file has , start sending messages after number exceeded. similar this:

<# …all world's indeed stage… #>
$file = 'c:\snort\log\alert.ids'
get-content $file -wait | foreach-object -begin {
 
$counter = 1
  $lines = @(get-content $file).count
} -process {
  if ($counter++ -gt $lines) {
   
cmd /c echo $_
  }
}

 

you may have alter initialization of counter variable. once test cmd statement, can use code in psremotingjob through start-job cmdlet.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Motherboard replacement

Cannot create Full Text Search catalog after upgrading to V12 - Database is not fully started up or it is not in an ONLINE state

Remote Desktop App - Error 0x207 or 0x607