Hello Guys ,
I need export log after move-item
Ex:
Move-Item *.rar -Destination $DiretoryBackupAM -Verbose | Add-Content F:\SRV-AM\log.txtBut in log file no show verbose details.
Are you can help me ?
Hello Guys ,
I need export log after move-item
Ex:
Move-Item *.rar -Destination $DiretoryBackupAM -Verbose | Add-Content F:\SRV-AM\log.txtBut in log file no show verbose details.
Are you can help me ?
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: Understanding Streams, Redirection, and Write-Host in PowerShell - Scripting Blog
… 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.
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 **********************
How about using redirection ?
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
This option is best for me
Really? Wow.