Copy-DiskToXen.ps1
<# .SYNOPSIS Copy a disk to Xen. .DESCRIPTION Copy a disk to an Xen. .PARAMETER Hostname Specifies the hostname of the XenSever system. .PARAMETER Port Specifies the network port of the XenSever system. .PARAMETER Username Specifies the login username for authenticating with the XenSever system. .PARAMETER Password Specifies the login password for authenticating with the XenSever system. .PARAMETER SrUuid Specifies the UUID of the storage repository on the XenServer system where the uploaded image will be created. .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 XenSever system. .PARAMETER Description Specifies a description to give to the uploaded image. .PARAMETER SslNoCheck If specified, ssl certificate checking is skipped for the XenSever 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-DiskToXen -FileName //smb.example.com//share/path/disk.vhd -Hostname "xen.acme.com" -Username bob -Password "xxxx" -Name "Win10" -LogFile xen-copy.log -OverwriteLog .EXAMPLE PS> Copy-DiskToXen -FileName ./disks/disk.vhd -Hostname "xen.acme.com" -Username bob -Password "xxxx" -Name "Win2019" -Description "v2" #> Function Copy-DiskToXen { [CmdletBinding()] Param( [Parameter(Mandatory = $True)] [string] $Hostname, [Parameter()] [string] $Port = 443, [Parameter(Mandatory = $True)] [string] $Username, [Parameter(Mandatory = $True)] [string] $Password, [Parameter(Mandatory = $True)] [string] $SrUuid, [Parameter(Mandatory = $True)] [string] $FileName, [Parameter(Mandatory = $True)] [string] $Name, [Parameter()] [string] $Description = "Uploaded by Citrix Image Uploader", [Parameter()] [switch] $SslNoCheck, [Parameter()] [string] $LogFile = "XenUpload.log", [Parameter()] [switch] $OverwriteLog ) Begin { InitUploadLog $LogFile $OverwriteLog VersionCheck } Process { try { $InformationPreference = "Continue" try { return Copy-ToXenDisk -Hostname $Hostname -Port $Port -Username $Username -Password $Password -Name $Name -SrUuid $SrUuid -FilePath $FileName -Description $Description -SslNoCheck $SslNoCheck.IsPresent -LogFileName $LogFile } catch { ThrowError ([UploaderError]::new("Failed to copy the disk to Xen", $_.Exception)) } } catch [UploaderError] { LogIfSslError $_ $PSCmdlet.ThrowTerminatingError($_) } catch { Log $_ LogIfSslError $_ $PSCmdlet.ThrowTerminatingError($_) } } } |