Not all output goes to the log

Hello everyone. I use Start-Transcript before starting my script, there is a block in the script in which the processes will terminate, I specified -verbose there and in the ISE console I see events about the termination of processes. But if you look at my log, there are no -verbose entries, I don’t see how I can get them to write to the log.

$Date = Get-Date -Format dd-MM-yyyy-hh-mm
Start-Transcript -Path C:\temp\Cleaning1C_$Date.txt

$nid = (Get-Process @('ragent', 'rmngr', 'rphost') -ErrorAction SilentlyContinue).id

if($nid -eq $null)
    {Write-Host 'No running processes "ragent", "rmngr", "rphost"'}
        Stop-Process -Id $nid -Verbose -Force | Wait-Process


Verbose messages are written to another stream than default output.

This might help you

@Olaf Hi
I read this article, thanks.
but does that mean i can’t use the pipeline?
doesn’t work like that

Stop-Process -Id $nid  -Force -Verbose 4>&1 | Wait-Process 

Does this only mean switching to a new line and abandoning the pipeline?

Stop-Process -Id $nid  -Force -Verbose 4>&1
Wait-Process -Id $nid

In PowerShell we pass objects down the pipeline. You’re trying to pass the objects and the verbose information down the pipeline. I wouldn’t expect this to work for cmdlets you actually want them to do something meaningful with your objects. :wink:

You may choose what’s important - the logging or the actual task you want to accomplish.

I’d separate the “workload” from the “logging”. A simple version would be something like this:

"'$(Get-Date -Format 'yyyyMMdd_HHmmss')' - Stopping process '$($nid)'" | Out-File -FilePath 'logfile.log' -Append
Stop-Process -Id $nid -Force | Wait-Process