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 filename
        [string] $Filename = 'objects',
        # 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,
        [string] $LanguageIdToKeep = ""
    )
    if(-not $Filename) {
        $Filename = 'objects'
    }
    $objectsTempPath = NewContainerSharedTempDirectory($ContainerName)
    if ($ExportTxtFile) {
        Export-NavContainerObjects -containerName $ContainerName -filter $Filter -objectsFolder $objectsTempPath -exportTo 'txt file'
        $sourceFile = (Get-ChildItem $objectsTempPath -Filter '*.txt')[0].FullName
        if($LanguageIdToKeep -ne "ALL") {
            #Copy objects bundle to the container
            Remove-ITIObjectTranslation -containerName $ContainerName -SourceFile $sourceFile -LanguageIdToKeep $LanguageIdToKeep
            #Copy objects bundle from the container
        }
        if ($SplitTxtFile) {
            Split-ITIObjectsTxtFile -Source $sourceFile -Destination $Destination
            Remove-Item $sourceFile -Force
        }
        Get-ChildItem -Path $objectsTempPath -Filter '*.txt' | ForEach-Object { Move-Item -Path $_.FullName -Destination (Join-Path $Destination "$Filename$($_.Extension)") }
    }
    if ($ExportFobFile) {
        Export-NavContainerObjects -containerName $ContainerName -filter $Filter -objectsFolder $objectsTempPath -exportTo 'fob file'
        Get-ChildItem -Path $objectsTempPath -Filter '*.fob' | ForEach-Object { Move-Item -Path $_.FullName -Destination (Join-Path $Destination "$Filename$($_.Extension)") }
    }
    Remove-Item -Path $objectsTempPath -Force -Recurse
}
Export-ModuleMember -Function Export-ITIObject