Hello
I’m setting up PS script which is to stop&start Windows service, copy and rename log file. This is script is run by the PRTG application (monitoring solution) when certain conditions are met. The script is executed by the platform on the platform server and makes mentioned changes on the remote computer. The problem that we have is that script execution stops once ‘Stop-Service’ is executed but there are still few lines to cover. There doesn’t seem to be any error or whatever. When I remove the ‘Stop-Service’ from the script then the full script is executed.
What I need to mention about is that the issue only is when this script is run by PRTG but when I run the script manually on the servers it works just fine. I’ve tried different variations of the script but the script is always stopping whenever it finishes the ‘Stop-Service’ execution.
At first glance it may look like user related issue (PRTG uses the same admin credts to start the script as when script is run manually) however the script itself runs. Do you know what might be the issue here? Please find below script lines that I use.
I’ll much appreciate your thoughts about it as I’ve spent much time troubleshooting it
Kind regards,
Karol
$service = Get-Service -ComputerName 123.123.123.123 -Name WindowsService Stop-Service -InputObject $service -Force 3>&1 2>&1 | Out-file E:\ProgramData\Notifications\EXE\log3.txt Move-Item -Path "\\123.123.123.123\C$\Program Files (x86)\PathToFile\file.log" -Destination "\\123.123.123.123\C$\Program Files (x86)\PathToFolder\archieve" 3>&1 2>&1 | Out-file E:\ProgramData\Notifications\EXE\log1.txt Get-ChildItem "\\123.123.123.123\C$\Program Files (x86)\Agilent Technologies\PathToFolder\archieve\file.log" | ForEach-Object { Rename-Item $_.FullName "$BackupFolder$($_.BaseName -replace " ", "_" -replace '\..*?$')-$(Get-Date -Format "ddMMyyyy")_oldlog.log" } 3>&1 2>&1 | Out-file E:\ProgramData\Notifications\EXE\log2.txt Start-Service -InputObject $service -Verbose