Generate log verbose after Move-item

Welcome Forums General PowerShell Q&A Generate log verbose after Move-item

Viewing 6 reply threads
  • Author
    Posts
    • #175870
      Participant
      Topics: 2
      Replies: 3
      Points: 29
      Rank: Member

      Hello Guys ,

       

      I need export log after move-item

      Ex:

      Move-Item *.rar -Destination $DiretoryBackupAM -Verbose | Add-Content F:\SRV-AM\log.txt

      But in log file no show verbose details.

      Are you can help me ?

    • #175885
      Participant
      Topics: 10
      Replies: 116
      Points: 450
      Helping Hand
      Rank: Contributor

      Verbose messages only show in their own output stream, so you need to redirect the output to standard output for it to show in the log.

      See: https://devblogs.microsoft.com/scripting/understanding-streams-redirection-and-write-host-in-powershell/

    • #175888
      Participant
      Topics: 1
      Replies: 1629
      Points: 3,061
      Helping Hand
      Rank: Community Hero

      ... or you make your life easier and use robocopy ... it's made for ... it's faster ... and writes a decent/good readable log for you if you want. 😉

    • #175894
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      Macros,

      You can also use Start-Transcript at the beginning of the move process.Below is an example.

      Start-Transcript -Path C:\Temp\Move-log.txt
      Transcript started, output file is C:\Temp\Move-log.txt
      
      Move-Item 'New Folder' -Destination Old -Verbose
      VERBOSE: Performing the operation "Move Directory" on target "Item: C:\Temp\New Folder Destination: C:\Temp\Old\New Folder".
      
      Move-Item '.\Old\New Folder' -Destination C:\Temp\ -Verbose
      VERBOSE: Performing the operation "Move Directory" on target "Item: C:\Temp\Old\New Folder Destination: C:\Temp\New Folder".
      
      Stop-Transcript
      Transcript stopped, output file is C:\Temp\Move-log.txt
      
      C:\Temp\Move-log.txt | Select-String -Pattern 'Transcript started' -Context 1,9999
        **********************
      > Transcript started, output file is C:\Temp\Move-log.txt
        PS C:\Temp> Move-Item 'New Folder' -Destination Old -Verbose
        VERBOSE: Performing the operation "Move Directory" on target "Item: C:\Temp\New Folder Destination: C:\Temp\Old\New Folder".
        PS C:\Temp> Move-Item '.\Old\New Folder' -Destination C:\Temp\ -Verbose
        VERBOSE: Performing the operation "Move Directory" on target "Item: C:\Temp\Old\New Folder Destination: C:\Temp\New Folder".
        PS C:\Temp> Stop-Transcript
        **********************
        Windows PowerShell transcript end
        End time: 20190910115631
        **********************
      
      
      
      
      • #175951
        Participant
        Topics: 2
        Replies: 3
        Points: 29
        Rank: Member

        This option is best for me

    • #175903
      Participant
      Topics: 40
      Replies: 166
      Points: 560
      Helping Hand
      Rank: Major Contributor
    • #175927
      Participant
      Topics: 0
      Replies: 115
      Points: 433
      Helping Hand
      Rank: Contributor

      Marcos,

      In case it wasn't obvious stream redirection is the preferred method. Below is what you would do.

      Move-Item *.rar -Destination $DiretoryBackupAM -Verbose *>&1 | Out-File F:\SRV-AM\log.txt -Append
    • #175957
      Participant
      Topics: 1
      Replies: 1629
      Points: 3,061
      Helping Hand
      Rank: Community Hero

      This option is best for me

      Really? Wow. 😉

Viewing 6 reply threads
  • You must be logged in to reply to this topic.