Powershell Copy-Item fails silently
- by R W
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 HH.mm.ss
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 HH.mm.ss
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?