1

I want to get the verbose result to a log file in powershell, I m able to see the verbose line in shell but unable to get it into variable or log file

I have used Tee-Object and given the file path but it dont seems to be working

Move-Item $source $_.File_Destination_Path -Force -Verbose | tee -Append -FilePath $Logfile

Expected output in logfile- "VERBOSE: Performing the operation "Move File...." But the result is blank, Please help me on this

fmsrv
  • 93
  • 1
  • 10
  • 1
    Read `Get-Help about_redirection` or view [online](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-5.1) –  Mar 29 '19 at 15:43
  • @LotPings it does'nt says about taking verbose output in text file, I have already tried `Tee-Object` but it does'nt gives any output of verbose – fmsrv Mar 29 '19 at 16:10
  • 2
    Use `4>&1` to merge the verbose output stream (4) with the success output stream (1). `Get-Help about_redirection` clearly explains that. –  Mar 29 '19 at 16:14

1 Answers1

1

As comments have mentioned, you should check out the about_Redirection msdn topic. In practice, it would look like:

Move-Item -Path $source -Destination $_.File_Destination_Path -Force -Verbose 4>&1 |
    Tee-Object -Append -FilePath $Logfile

Note the VERBOSE: bit is added by and you would need to append it yourself to have it visible in the output file.

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
  • able to get output on textfile, but the verbose output includes trail spaces between each char, Why it gives those space in file, but not their on screen – fmsrv Mar 30 '19 at 04:42
  • @fmsrv No idea what you're talking about, but it sounds like an encoding issue. – Maximilian Burszley Mar 30 '19 at 05:30
  • @fmsrv refer this [question](https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8) it will help to solve your query based on encoding, can try `-encoding utf8` – Vino Apr 01 '19 at 15:46