문제

I am using the PowerShell Copy-Item command to copy a directory with files to another location.

I want to display all the files on the console that are getting copied so that I know the status of the copy command.

도움이 되었습니까?

해결책

If you just want to see that in console, use the -verbose switch:

copy-item -path $from -destination $to -verbose

If you want to get a list of files or directories:

$files = copy-item -path $from -destination $to -passthru | ?{$_ -is [system.io.fileinfo]}

다른 팁

$source=ls c:\temp *.*
$i=1
$source| %{
    [int]$percent = $i / $source.count * 100
    Write-Progress -Activity "Copying ... ($percent %)" -status $_  -PercentComplete $percent -verbose
    copy $_.fullName -Destination c:\test 
    $i++
}

I suggest to try it this way:

(Copy-Item -Verbose C:\SrcDir\*.* c:\DstDir 4>&1).Message

Here the messages go to the output stream/pipeline rather than the verbose stream/pipeline and so will work more generally such as in TFS task scripts.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top