4. Dezember 2014 19:14
function ImportObjectPackToAllDatabases
{
# Use you own settings here:
$WorkingFolder = "C:\TEMP\BATCHIMPORTING"
$ImportAction = 'overwrite'
$Synchronize = 'No'
function ImportObjectsNAV70
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$ImportFile,
[String]$ImportAction
)
$ImportFile = $ImportFile.Trim("""")
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
if ($ObjectFile -ne "")
{
$NAVFolder = 'C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client'
$importfinsqlcommand = """$NAVFolder\finsql.exe"" command=importobjects, file=$ImportFile, servername=$Server, database=$Database,importAction=$ImportAction,logfile=$LogFile"
$Command = $importfinsqlcommand
Write-Debug $Command
cmd /c $Command
}
}
function ImportObjectsNAV71
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$ImportFile,
[String]$ImportAction
)
$ImportFile = $ImportFile.Trim("""")
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
if ($ObjectFile -ne "")
{
$NAVFolder = 'C:\Program Files (x86)\Microsoft Dynamics NAV\71\RoleTailored Client'
$importfinsqlcommand = """$NAVFolder\finsql.exe"" command=importobjects, file=$ImportFile, servername=$Server, database=$Database,importAction=$ImportAction,logfile=$LogFile"
$Command = $importfinsqlcommand
Write-Debug $Command
cmd /c $Command
}
}
function ImportObjectsNAV80
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$ImportFile,
[String]$ImportAction,
[String]$Synchronize
)
$ImportFile = $ImportFile.Trim("""")
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
if ($ObjectFile -ne "")
{
$NAVFolder = 'C:\Program Files (x86)\Microsoft Dynamics NAV\80\RoleTailored Client'
$importfinsqlcommand = """$NAVFolder\finsql.exe"" command=importobjects,file=$ImportFile,servername=$Server,database=$Database,importAction=$ImportAction,synchronizeschemachanges=$Synchronize,logfile=$LogFile"
$Command = $importfinsqlcommand
Write-Debug $Command
cmd /c $Command
}
}
# Start of processing #########
$ServerName = "KK-NB\SQL_NAV"
$directoryInfo = Get-ChildItem -Path .\DB_IMPORT_NAV70DE\ | Measure-Object
IF ($directoryInfo.count -eq 1)
{
$ImportFile = Get-ChildItem -Path .\DB_IMPORT_NAV70DE\
Get-ChildItem -Path .\DB_INDEX_NAV70DE\ |
foreach `
(
{
Write-host "Importing $ImportFile objects to NAV 2013 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
ImportObjectsNAV70 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-ImportFile $ImportFile `
-ImportAction $ImportAction
}
)
}
$ServerName = "KK-NB\NAVDEMO"
$directoryInfo = Get-ChildItem -Path .\DB_IMPORT_NAV71DE\ | Measure-Object
IF ($directoryInfo.count -eq 1)
{
$ImportFile = Get-ChildItem -Path .\DB_IMPORT_NAV71DE\
Get-ChildItem -Path .\DB_INDEX_NAV71DE\ |
foreach `
(
{
Write-host "Importing $ImportFile objects to NAV 2013 R2 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
ImportObjectsNAV71 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-ImportFile $ImportFile `
-ImportAction $ImportAction
}
)
}
$directoryInfo = Get-ChildItem -Path .\DB_IMPORT_NAV80DE\ | Measure-Object
IF ($directoryInfo.count -eq 1)
{
$ImportFile = Get-ChildItem -Path .\DB_IMPORT_NAV80DE\
Get-ChildItem -Path .\DB_INDEX_NAV80DE\ |
foreach `
(
{
Write-host "Importing $ImportFile objects to NAV 2015 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
ImportObjectsNAV80 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-ImportFile $ImportFile `
-ImportAction $ImportAction `
-Synchronize $Synchronize
}
)
}
}