i need a PS script to check for a sentance(errorline) from a log file in a location and if the error exists the it should rename a reg and if no error in log file it should exit can you help me with this plz<\/p>","upvoteCount":4,"answerCount":7,"datePublished":"2022-03-16T09:01:03.000Z","author":{"@type":"Person","name":"venky946","url":"https://community.spiceworks.com/u/venky946"},"suggestedAnswer":[{"@type":"Answer","text":"
i need a PS script to check for a sentance(errorline) from a log file in a location and if the error exists the it should rename a reg and if no error in log file it should exit can you help me with this plz<\/p>","upvoteCount":4,"datePublished":"2022-03-16T09:01:03.000Z","url":"https://community.spiceworks.com/t/need-a-script/827849/1","author":{"@type":"Person","name":"venky946","url":"https://community.spiceworks.com/u/venky946"}},{"@type":"Answer","text":"
What have you got so far?<\/p>\n
This is not a script writing service.<\/p>","upvoteCount":3,"datePublished":"2022-03-16T09:49:16.000Z","url":"https://community.spiceworks.com/t/need-a-script/827849/2","author":{"@type":"Person","name":"grsl","url":"https://community.spiceworks.com/u/grsl"}},{"@type":"Answer","text":"
You can use get-content to read the file and select-string to look for your error.<\/p>\n
Start there and see what you can come up with with a little google-fu, then if you are stuck, post what you have and we will try to help<\/p>","upvoteCount":1,"datePublished":"2022-03-16T09:54:09.000Z","url":"https://community.spiceworks.com/t/need-a-script/827849/3","author":{"@type":"Person","name":"brad","url":"https://community.spiceworks.com/u/brad"}},{"@type":"Answer","text":"
Oh sorry i thoigh somebody would help to get a PS script as i was looking for a PS script.<\/p>\n
to check for a sentance(error line) from a log file in a location and if the error exists the it should rename a reg and if no error in log file it should exit can you help me with this plz<\/p>\n
can i get any help in resolving this that would be really a great help<\/p>\n
#function<\/span> to check for license and chnage the servername in reg If you want to read a file, you can use Get-Content. If you want to search a file for a string, you may use Select-String. Select-String supports simple (non-regex) and regex matching. Select-String also supports reading a file line by line, which will work fine in your case.<\/p>\n Welcome to the community! We have a guide for new members linked at the top of the forum:<\/p>\n
\n$date = Get-date -format “yyyyMMdd”
\n$LogName = “LsiAgent.log”
\n$LogFile = Join-Path -Path “C:\\Program Files (x86)\\SysTrack\\LsiAgent.log” -ChildPath $LogName
\nGet-Content -Path $LogFile | Select-String -Patters “Error:”
\nif ($LogFile.contains(“License not found”))
\n{
\nMessage “No License on the selected server so changing the reg” RED
\nSet-ItemProperty -Path “HKLM:\\SOFTWARE\\WOW6432Node\\Lakeside Software\\Deploy” -Name “MasterSystem” -Value INSVCSIISM.IN.AS.COM<\/a> -Force
\n}
\nelse
\n{
\nMessage “no license issue found” Green
\n}<\/p>","upvoteCount":0,"datePublished":"2022-03-16T10:03:01.000Z","url":"https://community.spiceworks.com/t/need-a-script/827849/4","author":{"@type":"Person","name":"venky946","url":"https://community.spiceworks.com/u/venky946"}},{"@type":"Answer","text":"# file to check\n$LogFile = \"C:\\Program Files (x86)\\SysTrack\\LsiAgent.log\"\n# check for string in file contents\nif (Select-String -Path $LogFile -Pattern 'License not found' -SimpleMatch) {\n # write message to console only\n Write-Host 'No License on the selected server so changing the reg' -ForegroundColor Red\n Set-ItemProperty -Path 'HKLM:\\SOFTWARE\\WOW6432Node\\Lakeside Software\\Deploy' -Name 'MasterSystem' -Value 'INSVCSIISM.IN.AS.COM' -Force\n}\nelse {\n # write message to console only\n Write-Host 'No License Issue Found' -ForegroundColor Green\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2022-03-16T11:29:56.000Z","url":"https://community.spiceworks.com/t/need-a-script/827849/5","author":{"@type":"Person","name":"adminofthings","url":"https://community.spiceworks.com/u/adminofthings"}},{"@type":"Answer","text":"