none
Robocopy and powershell logfiles RRS feed

  • Question

  • Hi,

    I am using a powershell script that contains also some robocopy statements.

    Powershell writes a logfile:   "log-statements" | out-File -Append Logfile.txt

    I tried robocopy to use the same logfile: /Log+:Logfile.txt, but Robocopy will destroy the format of the powershell logfile. The powershell script write a plain text file. When robocopy write into the same logfile, the robocopy log contains only special characters and then also the powershell log contains special characters. When both scripts use the seperate logfiles everything is ok.

    Is there an easy way that powershell and robocopy can write - one after another - to the same txt-logfile?

    sonny


    Siegmund Sonntag

    Monday, July 22, 2013 8:42 AM

Answers

  • use in powershell:

    out-file file.txt -Encoding ascii

    then robocopy can write also in the same file.

    sonny

    "powershell"|out-filetest.txt-Encodingascii

    "powershell"|out-filetest.txt-Encodingascii

    "powershell"|out-filetest.txt-Encodingascii


    Siegmund Sonntag

    • Marked as answer by Sonny Sonntag Wednesday, July 31, 2013 1:29 PM
    Wednesday, July 31, 2013 1:29 PM

All replies

  • May help you.

    Have you tried Start-Transcript Command for PowerShell logs

    Eg:

    $log = "deploy-{0:yyyyMMdd-HHmmss}.RTF" -f (Get-Date)
    Start-Transcript -Path $log

    Write-Host "Doing Someting" -ForegroundColor Green
    Start-Sleep -Seconds 5

    Stop-Transcript
    exit 0

    Let me know if you have any issues.

    Monday, July 22, 2013 12:39 PM
  • Hi Chen,

    I don't use the Transcript commands for logging. In the Powershell Scripts I write log-information to a common log.txt file. The point is, when robocopy writes also to this log.txt file, the file format of the log.txt file is destroyed. The robocopy log is full of special characters and then the output of the powershell script that follows also.

    I am using now 2 separate logfiles for powershell and robocopy. In this case both *.txt files are ok and readable.

    sonny

     


    Siegmund Sonntag

    Wednesday, July 24, 2013 12:12 PM
  • use in powershell:

    out-file file.txt -Encoding ascii

    then robocopy can write also in the same file.

    sonny

    "powershell"|out-filetest.txt-Encodingascii

    "powershell"|out-filetest.txt-Encodingascii

    "powershell"|out-filetest.txt-Encodingascii


    Siegmund Sonntag

    • Marked as answer by Sonny Sonntag Wednesday, July 31, 2013 1:29 PM
    Wednesday, July 31, 2013 1:29 PM