VirtualFriend
Contributor
Contributor

Copy-VMGuestFile fails with large payload

I'm trying to copy a hyperic agent .msi installer payload from local to guest but it fails with the 381MB file. The error returned is:

Exception of type 'System.OutOfMemoryException' was thrown.
At line:1 char:76
+ get-item "C:\Hyperic\hyperic-hqee-installer-4.6.0.1.msi" | Copy-VMGuestFile <<<<  -Destination "C:\Hyperic" -VM "IIGCF-Win2k8-Test2" -LocalToGuest -GuestCredential $cred
    + CategoryInfo          : NotSpecified: (:) [Copy-VMGuestFile], ViError
    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_UploadFileToGuest_UploadError,VMware
   .VimAutomation.ViCore.Cmdlets.Commands.CopyVMGuestFile

Out of Memory... I tried a smaller .zip payload of 67MB, and it began to copy, but ultimately failed 1/3 in to it. Here is the error message now:

Copy-VMGuestFile : 1/26/2012 5:40:51 PM    Copy-VMGuestFile        The request was aborted: The request was canceled.
At line:1 char:78
+ get-item "C:\Hyperic\hyperic-hqee-agent-4.6.0.1-win32.zip" | Copy-VMGuestFile <<<<  -Destination "C:\Hyperic" -VM "IIGCF-Win2k8-Test2" -LocalToGuest -GuestCredential $cred
    + CategoryInfo          : NotSpecified: (:) [Copy-VMGuestFile], ViError
    + FullyQualifiedErrorId : Client20_VmGuestServiceImpl_UploadFileToGuest_UploadError,VMware
   .VimAutomation.ViCore.Cmdlets.Commands.CopyVMGuestFile

If I try to copy a small text document, the command works as intended. So my question is, how does one copy a "large" payload package to a guest VM, via powerCLI?

Thanks

0 Kudos
18 Replies
VirtualFriend
Contributor
Contributor

PowerCLI C:\> Get-PowerCLIVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 5.0 build 435427
---------------
Snapin Versions
---------------
   VMWare AutoDeploy PowerCLI 5.0 build 575
   VMWare ImageBuilder PowerCLI 5.0 build 575
   VMware License PowerCLI 5.0 build 395016
   VMWare vSphere PowerCLI 5.0 build 435427

0 Kudos
LucD
Leadership
Leadership

First try to update to 5.0.1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VirtualFriend
Contributor
Contributor

Updated to powerCLI 5.0.1

I'm trying with the larger file and I get the "Copy-VMGuestFile    The request was aborted: The request was canceled." error. It seems to timeout, but only if it would wait long enough the file would finish...

0 Kudos
LucD
Leadership
Leadership

Did you try with the parameter '-ToolsWaitSecs -1' ?

The risk is that the cmdlet will wait for ever if the VMware Tools do not respond anymore


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
VirtualFriend
Contributor
Contributor

Sort of. I tried with a value of 700 seconds, but I tried your suggestion of -1, but the result is the same. That seems to be the timeout for the VMware Tools. There is not timeout for the transfer process itself.

0 Kudos
VirtualFriend
Contributor
Contributor

I ended up placing the payload files on a shared directory and copied them over. It works OK doing it this way.

$payloadFilename = "hyperic-hqee-installer-4.6.0.1.msi"
$guestInstallPath = "C:\Hyperic"

$scriptCreateDir = "New-Item -type directory -Path"+$guestInstallPath
$payloadPath = "\\[IP Address]\hyperic\Server\$payloadFilename"

...

Invoke-VMScript -VM $VM -ScriptText "Copy-Item $payloadPath -Destination $guestInstallPath" -GuestCredential $cred

0 Kudos
GrantBrunton
Enthusiast
Enthusiast

Sorry to dig up an old thread but I have the same problem currently.

I am trying to copy some files into my VM Guests using the Copy-VMGuestFile command but it fails on some of the files that are over a couple GB with the 'System.OutOfMemoryException' error.

Unfortunately I do not have the luxury of being able to copy these files from a network share as the VM guests I am copying to are in an isolated network environment protected with vShield Edge.

I have tried increasing the memory of the guests I am copying to but this does not seem to work so I assume the memory problem is related to the server I am running the command from.

I am running vCenter 5.01b, ESXi 5.01 and powercli 5.01.

Does anyone know any solution for this or alternatives?

0 Kudos
LucD
Leadership
Leadership

An alternative, but it takes some more work, is to use an archive format (ZIP,RAR...) that allows you to split up the file in multiple parts.

And you need to unzip or unrar the file inside the guest once it is copied I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
GrantBrunton
Enthusiast
Enthusiast

Yea, thats not really an option I'd like to take :smileysilly:

That opens up a whole new level of issues including trying to find space to store the file parts both in and out of the VM.

I'm going to try increasing the memory on the server I'm running the script from and if that works writing in a parameter to check for available host memory before it will allow the files to copy. But that's still not a very desirable solution to waste host memory on a management server just to run this script.

0 Kudos
GrantBrunton
Enthusiast
Enthusiast

I just increased the memory of the server running the script and that doesn't make a difference to whether it fails or not either.

Does the powershell environment have a limited amount of memory available to it when a script runs or something?

EDIT: OK, so the powershell environemtn does have a memory limit that can be checked and changed with the following commands:

Get-Item wsman:localhost\Shell\MaxMemoryPerShellMB

Set-Item wsman:localhost\Shell\MaxMemoryPerShellMB <MB> -Force

I increased the amount of memory allocated to the powershell script (Mine was defaulted to 150MB) and instead of getting the 'OutOfmMemoryException' error I now just get the error 'The request was aborted: The request was canceled'.

It looks like this is now failing due to a time out problem as above but adding the option "-ToolsWaitSecs -1" does not fix this.

Guess I need to arrange some kind of alternative method somehow... maybe your last suggestion....  Smiley Sad

0 Kudos
LucD
Leadership
Leadership

As a last resort you could first try to upgrade to PowerCLI 5.1


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
GrantBrunton
Enthusiast
Enthusiast

Actually PowerCLI 5.1 seems to be slightly better.

I can now copy files that are 1GB but files that are 2GB or more are still failing. (previously could only copy up to a few hundred MB)

I have files up to 8GB to copy over but at least I can now split them into 1GB archive chunks instead of 200MB Smiley Happy

It also seems to know when it is going to fail now as it will give an error straight away instead of trying to copy for a while and then failing.

The error is either 'SystemOutOfMemory' if the powershell script memory is too low or 'The underlying connection was closed: Unable to connect to the remote server' if it the memory is enough.

0 Kudos
GrantBrunton
Enthusiast
Enthusiast

For anyone else who comes across this thread with the same problem later here is a snippet of the code I am using to copy files to my guest machines using 7zip to split files that are too big.

$sourcePath = "C:\Temp"
$filter = "*.*"
$destPath = "C:\Temp"
$vmGuest = Get-VM "VM"
$cred = Get-Credential

# Allow powershell environment enough memory to copy files
$mem = (Get-Item wsman:localhost\Shell\MaxMemoryPerShellMB).Value
Set-Item wsman:localhost\Shell\MaxMemoryPerShellMB 1024 -Force

# Check for 7zip
$scriptPath = Split-Path $MyInvocation.ScriptName
$7zip = ""
if (!(Test-Path ($scriptPath + "\7za.exe")))
{
    $response = [Microsoft.VisualBasic.Interaction]::MsgBox("Cannot  find 7zip executable in location:`n`t`"$($scriptPath)\7za.exe`"`nThis  will prevent large files from being able to be copied to the  guest.`n`nDo you wish to continue?",4,"Confirm")
    if ($response -ne "Yes") { exit }
}
else
{
    $7zip = $scriptPath + "\7za.exe"

    set-alias sevenzip "$($scriptPath)\7za.exe"
}

foreach ($file in (Get-ChildItem $sourcePath -filter $filter))
{
    "Copying $($file.Name)..."
    if ( ($file.Length/1024/1024) -gt 1024 )
    {
        if (!$7zip) { "file $($file.Name) too big to copy to guest without 7zip"; continue }
       
        sevenzip a -y -mx1 -v1024m "$($file.FullName).7z" "$($file.FullName)" | Out-Null
        if (!$?)
        {
            "Failed to split $($file.Name)"
            continue
        }

        Copy-VMGuestFile -LocalToGuest -Source "$($file.FullName).7z.*" -Destination $destPath -VM $vmGuest -GuestCredential $cred
        if (!$?)
        {
            "File $($file.Name) failed to copy to guest"
            $invokeOut = Invoke-VMScript -vm $vmGuest -ScriptType BAT -ScriptText "del `"$($destPath)\$($file.Name).7z.*`"" -GuestCredential $cred
            del "$($file.FullName).7z.*"
            continue
        }
        else
        {
            Copy-VMGuestFile -LocalToGuest -Source $7zip -Destination $destPath -VM $vmGuest -GuestCredential $cred
            $invokeOut = Invoke-VMScript -vm $vmGuest -ScriptType BAT -ScriptText "`"$($destPath)\7za.exe`" e -y -o`"$($destPath)`" `"$($destPath)\$($file.Name).7z.001`"" -GuestCredential $cred
            if (!($invokeOut -match "Everything is Ok")) { "Zip file $($file.Name) failed to extract properly" }
            $invokeOut = Invoke-VMScript -vm $vmGuest -ScriptType BAT -ScriptText "del `"$($destPath)\$($file.Name).7z.*`"" -GuestCredential $cred
            del "$($file.FullName).7z.*"
        }
    }
    else
    {
        Copy-VMGuestFile -LocalToGuest -Source $file.FullName -Destination $destPath -VM $vmGuest -GuestCredential $cred
        if (!$?)
        {
            "File $($file.Name) failed to copy to guest"
            $invokeOut = Invoke-VMScript -vm $vmGuest -ScriptType BAT -ScriptText "if exist `"$($destPath)\$($file.Name)`" del `"$($destPath)\$($file.Name)`"" -GuestCredential $cred
            continue
        }
    }
}

# Reset powershell environment memory setting
Set-Item wsman:localhost\Shell\MaxMemoryPerShellMB $mem -Force

0 Kudos
LucD
Leadership
Leadership

Great script, thanks for sharing.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Imranq
Enthusiast
Enthusiast


I had the same error when copying a file of 850mb. Smaller files worked ok. I noticed the active memory usage was reaching 1GB in total so the file failed to copy

I got around the issue by increasing the Memory in the Shell
Get-Item wsman:localhost\Shell\MaxMemoryPerShellMB

The above command displayed 1024 so I increased to 1500 with the below command.
Set-Item wsman:localhost\Shell\MaxMemoryPerShellMB 1500

The error still occurred I realised the powershell ise interface had to be closed and restarted.
After opening I ran the command to check the memory was still 1500
Get-Item wsman:localhost\Shell\MaxMemoryPerShellMB
Then I retried the Copy-VMGuestFile command and it worked.

0 Kudos
AlexNTTA
Contributor
Contributor

In case anyone looks at this thread, I had the same problem, but nothing here worked (didn't try the zip work around). I didn't want to upgrade PowerCLI too far as I'm running a 5.0 environment and feared my deployment scripts would not run properly. I tried 5.0.1, didn't work, but once I moved to 5.1, it did. In my case, I was only copying a 125MB file. It would get to 45MB and fail. I have to check if my deployment scripts still work with PowerCLI 5.1. Smiley Happy

0 Kudos
njqcteam
Contributor
Contributor

It seems to me I have faced the same on PowerCLI 5.5

Files 100Mb+ couldn't be copied to isolated VM.

I have noticed that every time it drops it happens after 5 minutes.

On heavy loaded host it takes more time to copy files.

That's why I didn't face it on another host with the same configuration.

I have found there is a parameter WebOperationTimeoutSeconds that has its default value of 300 seconds.

Set-PowerCLIConfiguration - vSphere PowerCLI Cmdlets Reference

After setting it to higher value (or even -1) I didn't face the issue again.

e.g.:

Set-PowerCLIConfiguration -WebOperationTimeoutSeconds 600 -Scope Session -Confirm:$false

Hope it will help someone else

LucD
Leadership
Leadership

You could also consider upgrading the PowerCLI version, that cmdlet has improved imho.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos