ObjectHandling/Export-NavObjectsForMerge.ps1
function Export-NavObjectsForMerge { Param( [Parameter(Mandatory=$false)] [string] $ContainerName, [Parameter(Mandatory=$true)] [string] $SourceFolder, [Parameter(Mandatory=$true)] [string] $DestinationFolder, [Parameter(Mandatory=$false)] [pscredential] $Credential ) if ($null -eq $ContainerName -or $ContainerName -eq "") { $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name') } if ($null -eq $Credential) { $NewCredential = New-CredentialFromEnvironmentJson if ($NewCredential -eq $false) { $Credential = (Get-Credential) } else { $Credential = $NewCredential } } if (!(Test-Path $DestinationFolder -PathType Container)) { New-Item $DestinationFolder -ItemType Directory -Force | Out-Null } $containerFolder = ((Get-NavContainerSharedFolders $ContainerName).GetEnumerator() | Where-Object { $_.Value -eq "C:\Run\my"}).Name $files = Get-ChildItem -Path $SourceFolder -Filter '*.TXT' $files | ForEach-Object { $type = $_.Name.Substring(0, 3).ToUpper() $id = $_.Name.Substring(3, $_.Name.Length - 7) switch ($type) { "TAB" { $objecttype = 1 } "PAG" { $objecttype = 8 } "REP" { $objecttype = 3 } "COD" { $objecttype = 5 } "QUE" { $objecttype = 9 } "XML" { $objecttype = 6 } "MEN" { $objecttype = 7 } } Export-NavContainerObjects -containerName $ContainerName -objectsFolder $containerFolder -filter "id=$id;type=$objecttype" -sqlCredential $Credential -exportTo 'txt file' -PreserveFormatting if (Test-Path (Join-Path $containerFolder "objects.txt") -PathType Leaf) { if ((Get-Item -Path (Join-Path $containerFolder "objects.txt")).Length -eq 0) { Copy-Item -Path $_.FullName -Destination (Join-Path $DestinationFolder $_.Name) -Force } else { Copy-Item -Path (Join-Path $containerFolder "objects.txt") -Destination (Join-Path $DestinationFolder $_.Name) -Force } Remove-Item (Join-Path $containerFolder "objects.txt") -Force } } } Export-ModuleMember Export-NavObjectsForMerge |