3. Dezember 2014 18:18
function CompileAllDatabases
{
# Note: There are 2 different server names in this example, also KK\NAVDEMO, it changes between CompileNAV70 and CompileNAV71
$ServerName = "KK-NB\SQL_NAV"
# Use your own filters and log file path here
$VersionListFilter = '"*OPP*"'
$ObjectFilter = "Version List=$VersionListFilter"
$WorkingFolder = "C:\Temp\BATCHCOMPILING"
function CompileNAV70
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$Filter
)
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
$NAVFolder = '"C:\Program Files (x86)\Microsoft Dynamics NAV\70\RoleTailored Client'
$compilefinsqlcommand = """$NAVFolder\finsql.exe"" command=compileobjects,servername=$Server,database=$Database,logfile=$LogFile"
if ($Filter -ne ""){$compilefinsqlcommand = "$compilefinsqlcommand,filter=$Filter"}
$Command = $compilefinsqlcommand
Write-Debug $Command
cmd /c $Command
}
function CompileNAV71
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$Filter
)
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
$NAVFolder = '"C:\Program Files (x86)\Microsoft Dynamics NAV\71\RoleTailored Client'
$compilefinsqlcommand = """$NAVFolder\finsql.exe"" command=compileobjects,servername=$Server,database=$Database,logfile=$LogFile"
if ($Filter -ne ""){$compilefinsqlcommand = "$compilefinsqlcommand,filter=$Filter"}
$Command = $compilefinsqlcommand
Write-Debug $Command
cmd /c $Command
}
function CompileNAV80
{
[CmdletBinding()]param (
[String]$WorkingFolder,
[String]$Server,
[String]$Database,
[String]$Filter,
[String]$Synchronize
)
$LogFile = "$WorkingFolder\$Server\$Database\navcommandresult.txt"
if (Test-Path "$LogFile\navcommandresult.txt") {Remove-Item "$LogFile\navcommandresult.txt"}
$NAVFolder = '"C:\Program Files (x86)\Microsoft Dynamics NAV\80\RoleTailored Client'
$compilefinsqlcommand = """$NAVFolder\finsql.exe"" command=compileobjects,servername=$Server,database=$Database,logfile=$LogFile,synchronizeschemachanges=$Synchronize"
if ($Filter -ne ""){$compilefinsqlcommand = "$compilefinsqlcommand,filter=$Filter"}
$Command = $compilefinsqlcommand
Write-Debug $Command
cmd /c $Command
}
Get-ChildItem -Path .\DB_INDEX_NAV70\ |
foreach `
(
{
Write-host "Compiling objects in NAV 2013 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
CompileNAV71 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-Filter $ObjectFilter
}
)
# Change of server name in this example, since the NAV 2013 R2 and NAV 2015 databases are located here
$ServerName = "KK-NB\NAVDEMO"
Get-ChildItem -Path .\DB_INDEX_NAV71\ |
foreach `
(
{
Write-host "Compiling objects in NAV 2013 R2 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
CompileNAV71 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-Filter $ObjectFilter
}
)
Get-ChildItem -Path .\DB_INDEX_NAV80\ |
foreach `
(
{
Write-host "Compiling objects in NAV 2015 database:" $_.Name
$databasename = [System.IO.Path]::GetFileNameWithoutExtension($_.Name)
CompileNAV80 `
-WorkingFolder $WorkingFolder `
-Server $ServerName `
-Database $databasename `
-Filter $ObjectFilter `
-Synchronize 'No'
}
)
}