Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a PowerShell 2.0 script running on Windows Server 2008 R2 64bit that copies some Hyper-V .vhd files to another server as a 'backup solution'.

The script gets a list of the .vhd's to copy then iterates over that list to copy them using Copy-Item. It also writes some logging info to a file as well. The files are copied to another server (Windows Server 2003 Sp2) into a directory compressed with NTFS compression.

One of the files isn't copied. It's relatively big ~ 68Gb. The others are 20Gb or less. The wierd thing is that during the copy process the file appears on the destination server and the log file generated seems to indicate the file is copied due to the difference in the times of the log file entries.

I see no error messages on the log file and nothing in the event log of either machine.

Here's the code that does the copy.

Get-ChildItem $VMSource *.vhd -Recurse | foreach-object {

    $time = Get-Date -format
    Add-Content $logFileName "$time : File Copy ($_) started" 

    $fullname = $_.FullName
    Add-Content $logFileName "$time : Copying $fullname to $VMDestination" 

    Copy-Item $fullname $VMDestination -Force -ErrorAction SilentlyContinue -ErrorVariable errors

    foreach($error in $errors)
        if ($error.Exception -ne $null)
            Add-Content $logFileName "'tERROR COPYING FILE : $($error.Exception)"

    $time = Get-Date -format
    Add-Content $logFileName "$time : File Copy ($_) finished"

I can only think there's some problem with copying a file that big to a compressed directory maybe? Any ideas?

share|improve this question

The problem was copy of that file in general. I tried copying the file in Explorer and it failed after about an hour with an error stating that part of the file was locked by another process.

I ended up amending the script to zip the file before moving it to the destination. The script now runs successfully albeit taking much longer.

Cheers for any answers tho.

share|improve this answer

You need to examine the -errorvariable option. If you use +errors instead of -errors you may retrieve additional errors.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.