Ok, I'm trying to tackle a problem that a piece of software that monitors for alarms can't apparently do.. and I'm trying to work around it.
I'm a powershell noob, so please pardon my inexperience.
What I need to do is:
- Search a folder for all XML that contain the word "Major".
- if it also contain the word "parsedxml" Do nothing and exit.
- else, write.Eventlog -Message ("insert the complete contents the pared XML file")
- then write "parsedxml" to the file so it knows it has already been checked if file still exists in the folder on the next search.
I have been working with Kaseya to try and get this done thru their tool and cannot get it to work. I can call a powershell script from Kaseya let's say every 5 minutes, but as I said.. I'm not a programmer by day and need a little help laying out how I would need to do this.
here is where I am at:
I am trying to parse an XML files from a directory where a keyword is defined, if the keyword is found true, take the contents of the xml and post it as the -Message portion of a Write Event and change that keyword so it isn't found the second time the script is run.
THIS WORKS, BUT PARSES EVERYTHING IN THE DIRECTORY.. I NEED TO FILTER ON XML’s ONLY WITH “MAJOR” IN THE FILE
Get-ChildItem C:\test\*.xml | ForEach { Write-EventLog –LogName Application –Source “Verint Alert”
` –EntryType Information –EventID 1
` -Message ("Triggered Alarm" + (Get-Content $_))
THIS CODE WILL CHANGE THE VALUE OF THE WORD “MAJOR” to “PARSED”
Get-ChildItem C:\test\*.xml -recurse | ForEach { (Get-Content $_ | ForEach {$_ -replace "Major", "Parsed"}) | Set-Content $_ }
I need to filter only on .xml files contain the “Major”. (Not sure how to do that)
Once the file is parsed, change the name from Major to Parsed so it’s not picked up again on the next check time the script is run.