ObjectHandling/Import-ObjectsFromFolder.ps1
<#
.synopsis Imports objects from a folder into a container .description Imports objects from a folder into a container and compiles them. If NAV 2018, enable symbol loading will be turned on .parameter ContainerName Container to be used. Can be provided in the settings.json .parameter Folder Folder the objects should be imported from .parameter Credential SQL Credentials to import objects .example Import-ObjectsFromFolder -ContainerName test -Folder C:\temp -Credential (Get-Credential) #> function Import-ObjectsFromFolder { Param( [Parameter(Mandatory=$false)] [string] $ContainerName, [Parameter(Mandatory=$true)] [string] $Folder, [Parameter(Mandatory=$false)] [pscredential] $Credential ) if ($null -eq $ContainerName -or $ContainerName -eq "") { $ContainerName = (Get-EnvironmentKeyValue -KeyName 'name') } if ($null -eq $Credential) { $NewCredential = Get-CredentialFromEnvironmentJson if ($NewCredential -eq $false) { $Password = ("01000000d08c9ddf0115d1118c7a00c04fc297eb01000000f2d5880bd296784999333fc74a891a790000000002000000000003660000c000000010000000aab554bf75952d24752731bd3580c3100000000004800000a0000000100000002d614183cc102d517a1830bf036a81c51800000023f5b6d355199ef36b42f88dea120bc2a0218c02be82d4a614000000b56ce44dddc0077c795ed1e30d92802a5a761a93" | ConvertTo-SecureString) $Credential = [PSCredential]::new('sa', $Password) } else { $Credential = [PSCredential]::new('sa', $NewCredential.Password) } } [version]$platform = (docker inspect $ContainerName | ConvertFrom-Json).Config.Labels.version if ($platform.Major -eq 11) { Enable-SymbolLoading -ContainerName $ContainerName Start-Sleep -Seconds 5 } if (Test-Path $Folder -PathType Container) { $files = Get-ChildItem -Path $folder -include ('*.TXT', '*.FOB') -Recurse $files | ForEach-Object { Import-ObjectsToNavContainer -containerName $ContainerName -objectsFile $_.FullName -sqlCredential $Credential -ImportAction Overwrite -SynchronizeSchemaChanges Force } Compile-ObjectsInNavContainer -containerName $ContainerName -SynchronizeSchemaChanges Force -sqlCredential $Credential } else { Write-Output "No Objects found" } } Export-ModuleMember Import-ObjectsFromFolder |