20. Januar 2016 10:11
function ResetObjectDateTime
{
[CmdletBinding()]
Param
(
[String][Parameter(Mandatory=$True)]
$PathObjectPack
)
if (-not (Test-Path $PathObjectPack))
{Throw "File $PathObjectPack does not exist"}
$WorkingFolder = "$env:temp\TempNAVobjects"
if (-not (Test-Path $WorkingFolder)) {New-item $WorkingFolder -ItemType Directory -force}
else {Remove-Item -path $WorkingFolder\*.* -recurse}
$ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
$NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + '_DefaultDateTime' + (Get-Item $PathObjectPack).Extension
Split-NAVApplicationObjectFile -Source $PathObjectPack -Destination $WorkingFolder -PreserveFormatting
Get-ChildItem -Path $WorkingFolder\*.txt |
ForEach `
(
{
# $_ -> C:\Users\KAIKOW~1\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
# $_.Name -> TAB25.TXT
# $_.FullName -> C:\Users\Kai Kowalewski\AppData\Local\Temp\TempNAVobjects\TAB25.TXT
$CurrFileName = (Get-Item $_).name
$CurrVersionList = (Get-NAVApplicationObjectProperty -Source $_ ).VersionList
$CurrDate = (Get-NAVApplicationObjectProperty -Source $_ ).GetDate
$CommaPos = $CurrVersionList.IndexOf(',')
if ($CommaPos -gt -1)
{$CurrVersionList = $CurrVersionList.substring(0,$CommaPos)}
$NotFound = $False
Switch ($CurrVersionList)
{
'OPP7.00' {$ObjectDate = '11.11.12'}
'OPP7.01' {$ObjectDate = '30.12.12'}
'OPP7.02' {$ObjectDate = '20.05.13'}
'OPP7.02.01' {$ObjectDate = '20.05.13'}
'OPP7.02.02' {$ObjectDate = '30.05.13'}
"OPP7.02.03" {$ObjectDate = '04.06.13'}
"OPP7.03" {$ObjectDate = '29.11.13'}
"OPP7.03" {$ObjectDate = '29.11.13'}
"OPP7.04" {$ObjectDate = '16.01.14'}
"OPP7.05" {$ObjectDate = '16.01.14'}
"OPP8.00" {$ObjectDate = '24.10.14'}
"OPP8.00.06" {$ObjectDate = '01.04.15'}
'OPP9.00' {$ObjectDate = '23.10.15'}
"OPP9.00.01" {$ObjectDate = '06.11.15'}
"OPP9.00.02" {$ObjectDate = '26.11.15'}
"OPP9.00.03" {$ObjectDate = '10.12.15'}
"OPP9.10" {$ObjectDate = '22.04.16'}
default {$ObjectDate = $CurrDate
$NotFound = $True
}
}
if ($NotFound) {Write-host "$CurrFileName with $CurrVersionList unknown. Add this to the Switch statement if necessary." -ForegroundColor Yellow}
$BaseDateTimeString = "$ObjectDate 12:00:00"
if (-not $NotFound)
{Set-NAVApplicationObjectProperty -TargetPath $_ -DateTimeProperty $BaseDateTimeString -modifiedProperty No}
Write-host
Write-host "Date in $CurrFileName with $CurrVersionList : $ObjectDate"
}
)
Join-NAVApplicationObjectFile -Destination $NewObjectPackFullName -Source $WorkingFolder\*.txt -Force
Remove-Item -path $WorkingFolder -recurse
}