Copy-DiskToAWS.ps1

<#

.SYNOPSIS
Copy a disk to AWS.

.DESCRIPTION
Copy a disk to an AWS EC2 snapshot.

.PARAMETER FileName
Specifies the filename of the disk to be copied. Can be local or on a share.

.PARAMETER Description
Specifies a description to give to the snapshot.

.PARAMETER Tags
Specifies tags to label the snapshot with.

.PARAMETER Region
Specifies the AWS region to create the snapshot in.

.PARAMETER ProfileName
Specifies the name of a profile containing the AWS credentials to use.

.PARAMETER Threads
Specifies the number of threads to use for uploading.

.PARAMETER LogFile
Specifies the path to the file to log to. ".\Upload.log" is the default.

.PARAMETER OverwriteLog
If specified the log file is overwritten otherwise it is appended to.

.INPUTS
None.

.OUTPUTS
System.String. The ID of the EC2 snapshot the disk was copied to.

.EXAMPLE

PS> Copy-DiskToAWS -FileName //smb.example.com//share/path/disk.vhd -LogFile aws-copy.log -OverwriteLog

snap-b4191a9783f1f568e

.EXAMPLE

PS> Copy-DiskToAWS -FileName ./disks/disk.vhd -Description "example upload" -Tags @{Organization = "ACME"; User = "RoadRunner"}

snap-86e584cb0cbeb4a83

#>


Function Copy-DiskToAWS
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True)]
        [string] $FileName,

        [Parameter()]
        [string] $Description,

        [Parameter()]
        [HashTable] $Tags,

        [Parameter()]
        [string] $Region,

        [Parameter()]
        [string] $ProfileName,

        [Parameter()]
        [int] $Threads,

        [Parameter()]
        [string] $LogFile,

        [Parameter()]
        [switch] $OverwriteLog
    )

    Begin
    {
        InitUploadLog $LogFile $OverwriteLog

        VersionCheck $CustomerId
    }

    Process
    {
        try
        {
            $InformationPreference = "Continue"
            try
            {
                return UploadToAws $FileName $ProfileName $Region $Description $Tags $Threads $Global:UploadLogFile
            }
            catch
            {
                ThrowError ([UploaderError]::new("Failed to copy the disk to AWS", $_.Exception))
            }
        }
        catch [UploaderError]
        {
            LogIfSslError $_
            $PSCmdlet.ThrowTerminatingError($_)
        }
        catch
        {
            Log $_
            LogIfSslError $_
            $PSCmdlet.ThrowTerminatingError($_)
        }
    }
}