functions/Send-TdImportFile.TempPoint.ps1

function Send-TdImportFile {
<#
    .SYNOPSIS
        Sends a file to your TOPdesk webdav import file
     
    .DESCRIPTION
        A detailed description of the Send-TdImportFile function.
     
    .PARAMETER File
        A description of the File parameter.
     
    .PARAMETER Credential
        A description of the Credential parameter.
     
    .EXAMPLE
                PS C:\> Send-TdImportFile -Credential $value1
     
    .NOTES
        Additional information about the function.
#>

    
    [CmdletBinding()]
    param
    (
        [ValidateScript({
                if (-Not ($_ | Test-Path)) {
                    throw "File or folder does not exist"
                }
                if (-Not ($_ | Test-Path -PathType Leaf)) {
                    throw "The Path argument must be a file. Folder paths are not allowed."
                }
                return $true
            })]
        [System.IO.FileInfo]
        $File,
        
        [Parameter(Mandatory = $true)]
        [PSCredential]
        $Credential
    )
    
    begin {
        Write-PSFMessage -Level InternalComment -Message "Bound parameters: $($PSBoundParameters.Keys -join ", ")" -Tag 'debug', 'start', 'param'
        
        $FileName = Get-Item -Path $File | Select-Object -ExpandProperty Name
        
        $UploadUrl = (Get-TdUrl -ErrorAction Stop) + '/webdav/import' + "/$FileName"
        Write-PSFMessage "UploadUrl: $UploadUrl" -Level InternalComment
    }
    process {
        
        try {
            Write-PSFMessage 'Uploading File...' -Level Verbose
            $Params = @{
                Uri            = $UploadUrl
                Method        = 'Put'
                InFile        = $File
                Credential  = $Credential
                ContentType = 'application/x-www-form-urlencoded'
            }
            Invoke-WebRequest Pparams
        }
        catch {
            
            switch ($_.Exception.Response.StatusCode.Value__) {
                401 {
                    Write-Error "Invalid Credentials."
                }
                403 {
                    Write-Error "Unable to upload to TOPdesk. Make sure that you have write permissions on $ImportDirectory directory."
                }
                409 {
                    Write-Error "Unknown directory on remote. Make sure that $ImportDirectory directory exists."
                }
                500 {
                    Write-Error "Unknown server error."
                }
            }
        }
        end {
            
        }
    }