30. März 2016 15:11
[datetime]$OldFormatDateTime = [datetime]::ParseExact(($OldDateString + ' ' + $OldTimeString), "dd-MM-yy HH:mm:ss",$null)
function SetLocalObjectDateFormat
{
[CmdletBinding()]
Param
(
[String][Parameter(Mandatory=$True)]
$PathObjectPack
)
$argspath = resolve-path $PathObjectPack
$WorkingFolder = split-path $argspath -Parent
$ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
$NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + '_LocalDateFormat' + (Get-Item $PathObjectPack).Extension
New-Item -Path $WorkingFolder -type directory -Name TempNAVobjects -Force
$WorkingSubFolder = "$WorkingFolder\TempNAVobjects\"
remove-item $WorkingSubFolder\*.* -Recurse
Split-NAVApplicationObjectFile -Source $argspath -Destination $WorkingFolder\TempNAVobjects -PreserveFormatting -Force
foreach ($file in get-ChildItem -Path $WorkingSubFolder\ | Where {$_.extension -eq '.TXT'})
{
#Get-NAVApplicationObjectProperty -Source $File.FullName
$OldDateString = (Get-NAVApplicationObjectProperty -Source $File.FullName).Date
$OldTimeString = (Get-NAVApplicationObjectProperty -Source $File.FullName).Time
# Write-host "$file.FullName $OldDateString $OldTimeString"
# Source Format is set here
[datetime]$OldFormatDateTime = [datetime]::ParseExact(($OldDateString + ' ' + $OldTimeString), "dd-MM-yy HH:mm:ss",$null)
$OldDateTimeString = "$OldDateString $OldTimeString"
#Write-host $OldDateTimeString
# Set local format here
$NewDateTimeString = $OldFormatDateTime.ToString("dd.MM.yy HH:mm:ss")
#Write-host $NewDateTimeString
Set-NAVApplicationObjectProperty -Target $file.FullName -DateTimeProperty (Get-Date $NewDateTimeString -Format g)
}
Write-Host "Deleting old object files…"
IF (Test-Path $WorkingSubFolder\allobjects.txt) {Remove-Item $WorkingSubFolder\allobjects.txt}
IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
Write-Host "Joining discrete NAV object files…"
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\TAB*.txt -Destination $WorkingSubFolder\alltables.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\REP*.txt -Destination $WorkingSubFolder\allreports.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\COD*.txt -Destination $WorkingSubFolder\allcodeunits.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\XML*.txt -Destination $WorkingSubFolder\allxmlports.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\MEN*.txt -Destination $WorkingSubFolder\allmenusuites.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\PAG*.txt -Destination $WorkingSubFolder\allpages.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\QUE*.txt -Destination $WorkingSubFolder\allqueries.txt
Write-Host "Concatenating object files…"
IF (Test-Path $WorkingSubFolder\alltables.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\alltables.txt)}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allreports.txt)}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allcodeunits.txt)}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allxmlports.txt)}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allmenusuites.txt)}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allpages.txt)}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allqueries.txt)}
IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
Move-Item $WorkingSubFolder\AllObjects.txt $NewObjectPackFullName -Force
}
11. Mai 2017 15:12
Kowa hat geschrieben:[…]da NAV ja leider nach wie vor kein einheitliches ISO-Datumsformat wie YYYY-MM-DD verwendet.
29. Januar 2018 12:27
function SetLocalObjectDateFormatDlg
{
Function Get-FileName($initialDirectory)
{
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "NAV Object Files (*.txt)|*.txt"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
}
$inputfile = Get-FileName -initialdirectory "$env:HOMEDRIVE\temp"
if ($inputfile -eq "") {throw 'Please select a file'}
$argspath = resolve-path $inputfile
$WorkingFolder = split-path $argspath -Parent
$ObjectPackFileBaseName = (Get-Item $inputfile).Basename
$NewObjectPackFullName = (Get-Item $inputfile).DirectoryName + '\' + (Get-Item $inputfile).Basename + '_LocalDateFormat' + (Get-Item $inputfile).Extension
New-Item -Path $WorkingFolder -type directory -Name TempNAVobjects -Force
$WorkingSubFolder = "$WorkingFolder\TempNAVobjects\"
remove-item $WorkingSubFolder\*.* -Recurse
Split-NAVApplicationObjectFile -Source $argspath -Destination $WorkingFolder\TempNAVobjects -PreserveFormatting -Force
foreach ($file in get-ChildItem -Path $WorkingSubFolder\ | Where {$_.extension -eq '.TXT'})
{
#Get-NAVApplicationObjectProperty -Source $File.FullName
$OldDateString = (Get-NAVApplicationObjectProperty -Source $File.FullName).Date
$OldTimeString = (Get-NAVApplicationObjectProperty -Source $File.FullName).Time
# Write-host "$file.FullName $OldDateString $OldTimeString"
# Source Format is set here
[datetime]$OldFormatDateTime = [datetime]::ParseExact(($OldDateString + ' ' + $OldTimeString), "dd-MM-yy HH:mm:ss",$null)
$OldDateTimeString = "$OldDateString $OldTimeString"
#Write-host $OldDateTimeString
# Set local format here
$NewDateTimeString = $OldFormatDateTime.ToString("dd.MM.yy HH:mm:ss")
#Write-host $NewDateTimeString
Set-NAVApplicationObjectProperty -Target $file.FullName -DateTimeProperty (Get-Date $NewDateTimeString -Format g)
}
Write-Host "Deleting old object files…"
IF (Test-Path $WorkingSubFolder\allobjects.txt) {Remove-Item $WorkingSubFolder\allobjects.txt}
IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
Write-Host "Joining discrete NAV object files…"
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\TAB*.txt -Destination $WorkingSubFolder\alltables.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\REP*.txt -Destination $WorkingSubFolder\allreports.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\COD*.txt -Destination $WorkingSubFolder\allcodeunits.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\XML*.txt -Destination $WorkingSubFolder\allxmlports.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\MEN*.txt -Destination $WorkingSubFolder\allmenusuites.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\PAG*.txt -Destination $WorkingSubFolder\allpages.txt
Join-NAVApplicationObjectFile -Source $WorkingSubFolder\QUE*.txt -Destination $WorkingSubFolder\allqueries.txt
Write-Host "Concatenating object files…"
IF (Test-Path $WorkingSubFolder\alltables.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\alltables.txt)}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allreports.txt)}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allcodeunits.txt)}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allxmlports.txt)}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allmenusuites.txt)}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allpages.txt)}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allqueries.txt)}
IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
Move-Item $WorkingSubFolder\AllObjects.txt $NewObjectPackFullName -Force
}