ObjectFilesHandling/Export-ITIObject.ps1

<#
.SYNOPSIS
    Exports all the .txt files to the specified container
.DESCRIPTION
    Joins all the .txt files in the specified directory, exports the objects to the database and compiles the exported objects
.EXAMPLE
    Export-ITIObject -ContainerName bccontainer -SourcePath ~/MyProject/Apps
.NOTES
    The command uses commands from NavContainerHelper to export and compile the objects
#>

function Export-ITIObject {
    [CmdletBinding()]
    param (
        # Container to export the objects to
        [Parameter(Mandatory=$true)]
        [string] $ContainerName,
        # Directory where the .txt objects are stored
        [string] $Destination = './Apps',
        # Exported objects filter
        [string] $Filter = "Date='';Time=''",
        # Specifies whether to export the .fob file
        [bool] $ExportFobFile = $false,
        # Specifies whether to export the .txt file
        [bool] $ExportTxtFile = $true,
        # Specifies whether to split the .txt file into single object files and place them in subfolders based on the object type
        [bool] $SplitTxtFile = $true
    )
    $objectsTempPath = NewContainerSharedTempDirectory($ContainerName)
    if ($ExportTxtFile) {
        Export-NavContainerObjects -containerName $ContainerName -filter $Filter -objectsFolder $objectsTempPath -exportTo 'txt file'
        Get-ChildItem $objectsTempPath | Move-Item -Destination $Destination
        if ($SplitTxtFile) {
            $sourceFile = (Get-ChildItem $Destination -Filter '*.txt')[0].FullName
            Split-ITIObjectsTxtFile -Source $sourceFile -Destination $Destination
            Remove-Item $sourceFile -Force
        }
    }
    if ($ExportFobFile) {
        Export-NavContainerObjects -containerName $ContainerName -filter $Filter -objectsFolder $objectsTempPath -exportTo 'fob file'
        Get-ChildItem $objectsTempPath | Move-Item -Destination $Destination
    }
    Remove-Item -Path $objectsTempPath -Force -Recurse
}
Export-ModuleMember -Function Export-ITIObject