Forum Discussion

TampaCCT's avatar
TampaCCT
Copper Contributor
Oct 09, 2020

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

 

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?

 

 

Resources