Script execution stops in the middle after Stop-Service cmdlet+PRTG

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 :wink:

Kind regards,

$service = Get-Service -ComputerName -Name WindowsService
Stop-Service -InputObject $service -Force 3>&1 2>&1 | Out-file E:\ProgramData\Notifications\EXE\log3.txt
Move-Item -Path "\\\C$\Program Files (x86)\PathToFile\file.log" -Destination "\\\C$\Program Files (x86)\PathToFolder\archieve" 3>&1 2>&1 | Out-file E:\ProgramData\Notifications\EXE\log1.txt
Get-ChildItem "\\\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

I forgot to add one more thing. When ‘Stop-Service’ is successfully executed then the ‘Move-Item’ doesn’t provide any output to the log1.txt. File isn’t even created a that stage.

Kind regards,

karwie60, welcome to Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

When you post code, error messages, sample data or console output format it as code, please.
In the “Text” view you can use the code tags “CRAYON“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
Thanks in advance.

My DOS is rusty. What is this ‘3>&1 2>&1’ redirection doing?