Generate log verbose after Move-item

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

This topic contains 7 replies, has 5 voices, and was last updated by

 
Participant
1 week, 1 day ago.

  • Author
    Posts
  • #175870

    Participant
    Topics: 2
    Replies: 3
    Points: 28
    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: 59
    Points: 141
    Helping Hand
    Rank: Participant

    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: 1528
    Points: 2,581
    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: 100
    Points: 363
    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: 28
      Rank: Member

      This option is best for me

  • #175903

    Participant
    Topics: 37
    Replies: 155
    Points: 479
    Helping Hand
    Rank: Contributor
  • #175927

    Participant
    Topics: 0
    Replies: 100
    Points: 363
    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: 1528
    Points: 2,581
    Helping Hand
    Rank: Community Hero

    This option is best for me

    Really? Wow. 😉

You must be logged in to reply to this topic.