SOLVED

remove-item -Verbose shows on host but not on log file.

Copper Contributor

 

First post new to Powershell moving away from batch commands.  Simple command Delete a file and output the results to file(log).

 

In batch command:   del myFile.log >> myLogFile.txt

All output goes to the file.  Nothing on the screen. (Normal behavior)

 

Powershell Version 5.1: Remove-item test.log -Verbose | Add-content -path "C:\temp\myLogFile.txt"

No Output blank file.    Verbose shows on the host screen. OK, verbose is not an object. Is it a string sent to the host?  

 

Powershell Version 5.1:

Remove-item test.log -Verbose *> "C:\temp\myLogFile.txt"

No Output blank file.   OK, not a string.    Is it a process Stream?

 

Powershell Version 5.1:  Remove-item test.log -Verbose 4>&1 | add-content "C:\temp\myLogFile.txt"

 

Remove-item test.log -Verbose 4>&1 | add-content "C:\temp\myLogFile.txt"

 

OK, That worked.  The command redirects the verbose output to Success Stream that add-content can see as a string object.

 

Here is the question.  Is there a better way to code in Powershell 5.1 to get the same results?  Can verbose redirect be written in an easier to read manor?

 

 

1 Reply
best response confirmed by TampaCCT (Copper Contributor)
Solution

@TampaCCT 

Read my post from here,

https://www.powershellcenter.com/2020/08/14/powershell-dump-the-console-output-to-a-file-output-redi...

 

I explain this 

This is related to output redirection,

use *> to redirect the output from the console to the file

 

This is a stream, and I don't think there is a better way to redirect the stream in the console to a file, as usually verbose are meant for troubleshooting only, 

 

 

-------------------

If this answer seems good to you, please click on Best Response

Thanks

1 best response

Accepted Solutions
best response confirmed by TampaCCT (Copper Contributor)
Solution

@TampaCCT 

Read my post from here,

https://www.powershellcenter.com/2020/08/14/powershell-dump-the-console-output-to-a-file-output-redi...

 

I explain this 

This is related to output redirection,

use *> to redirect the output from the console to the file

 

This is a stream, and I don't think there is a better way to redirect the stream in the console to a file, as usually verbose are meant for troubleshooting only, 

 

 

-------------------

If this answer seems good to you, please click on Best Response

Thanks

View solution in original post