Daryl
Daryl

Reputation: 15

Powershell Move-Item logging

I would like some assistance getting a powershell script to work correctly. A piece of it is pasted below. Basically what I'm trying to do is to move all files in various subdirectories to another location. I can get the files to move and the folders to create fine, I'm just having a problem with getting the results to a text file. I've tried using out-file, but the txt file is empty. I've also tried start-transcript, but notepad doesn't seem to see line breaks and all the text bleeds together. Is there a better way to go about this? I'm using this basic command for testing.

Start-Transcript c:\log.txt
Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force
Stop-Transcript

Upvotes: 1

Views: 14060

Answers (1)

Eris
Eris

Reputation: 7638

You may just need to collapse the output file descriptors. According to the about_Redirection page, it should work if you do the following:

Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force *>&1 | 
    Out-File -FilePath $MyLogPath

Or if you want to see the output at the same time

Move-Item c:\temp\*.* C:\Temp\2014 -Verbose -Force *>&1 |
    Tee-File -FilePath $MyLogPath

Upvotes: 1

Related Questions