Citrix.Image.Uploader/Copy-DiskToAHV.ps1

<#

.SYNOPSIS
Copy a disk to AHV.

.DESCRIPTION
Copy a disk to an AHV.

.PARAMETER Hostname
Specifies the hostname of the Nutanix system.

.PARAMETER Port
Specifies the network port of the Nutanix system.

.PARAMETER Username
Specifies the login username for authenticating with the Nutanix system.

.PARAMETER Password
Specifies the login password for authenticating with the Nutanix system.

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

.PARAMETER Name
Specifies the name to give to the uploaded image on the Nutanix system.

.PARAMETER Description
Specifies a description to give to the uploaded image.

.PARAMETER SslNoCheck
If specified, ssl certificate checking is skipped for the Nutanix host.

.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 image the disk was copied to.

.EXAMPLE

PS> Copy-DiskToAHV -FileName //smb.example.com//share/path/disk.vhd -Hostname "ahv.acme.com" -Username bob -Password "xxxx" -Name "Win10" -LogFile ahv-copy.log -OverwriteLog


.EXAMPLE

PS> Copy-DiskToAHV -FileName ./disks/disk.vhd -Hostname "ahv.acme.com" -Username bob -Password "xxxx" -Name "Win2019" -Description "v2"


#>


Function Copy-DiskToAHV
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $True)]
        [string] $Hostname,
        [Parameter()]
        [string] $Port = 9440,

        [Parameter(Mandatory = $True)]
        [string] $Username,
        [Parameter(Mandatory = $True)]
        [string] $Password,

        [Parameter(Mandatory = $True)]
        [string] $FileName,

        [Parameter(Mandatory = $True)]
        [string] $Name,
        [Parameter()]
        [string] $Description = "Uploaded by Citrix Image Uploader",

        [Parameter()]
        [switch] $SslNoCheck,

        [Parameter()]
        [string] $LogFile = "AhvUpload.log",

        [Parameter()]
        [switch] $OverwriteLog
    )

    Begin
    {
        InitUploadLog $LogFile $OverwriteLog

        VersionCheck
    }

    Process
    {
        try
        {
            $InformationPreference = "Continue"
            try
            {
                return Copy-ToAhvDisk -Hostname $Hostname -Port $Port -Username $Username -Password $Password -Name $Name -FilePath $FileName -Description $Description -SslNoCheck $SslNoCheck.IsPresent -LogFileName $LogFile
            }
            catch
            {
                ThrowError ([UploaderError]::new("Failed to copy the disk to AHV", $_.Exception))
            }
        }
        catch [UploaderError]
        {
            LogIfSslError $_
            $PSCmdlet.ThrowTerminatingError($_)
        }
        catch
        {
            Log $_
            LogIfSslError $_
            $PSCmdlet.ThrowTerminatingError($_)
        }
    }
}