30. Juli 2015 17:35
function FobToIndexFiles
{
$FileExists = Test-Path $args
If ($FileExists -eq $False) {Throw "No $args file exists at this location."}
$FileExtension = [System.IO.Path]::GetExtension($args)
if ($FileExtension -eq '.fob')
{
$WorkingFolder = "$env:temp\TEMPINDEX\"
If (Test-Path $WorkingFolder) {Remove-Item $WorkingFolder -Recurse -Force}
$reader = [System.IO.File]::OpenText($args)
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
$FirstCharacter = $line.Substring(0,1)
IF ([byte][char]$FirstCharacter -eq 26) { break }
$ShortObjectType = $line.Substring(0,3).ToUpper()
Switch ($ShortObjectType)
{
"FOR" {break}
"DAT" {break}
}
if ($FirstCharacter -ne ' ')
{
Write-Host $line
$ObjectID = $line.Substring(10,10)
$ObjectID = $ObjectID.Trim()
$NewFileName = "$ShortObjectType" + "$ObjectID" +'.TXT'
$ExportPath = $WorkingFolder + $NewFileName
New-Item $ExportPath -ItemType file -force
}
}
}
finally {
$reader.Close()
}
}
else
{Throw 'Please use a Dynamics NAV object file with *.fob extension for this script.'}
}
30. Juli 2015 22:50
function FobToIndexFilesFormToPage
{
$FileExists = Test-Path $args
If ($FileExists -eq $False) {Throw "No $args file exists at this location."}
$FileExtension = [System.IO.Path]::GetExtension($args)
if ($FileExtension -eq '.fob')
{
$WorkingFolder = "$env:temp\TEMPINDEX\"
If (Test-Path $WorkingFolder) {Remove-Item $WorkingFolder -Recurse -Force}
$reader = [System.IO.File]::OpenText($args)
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
$FirstCharacter = $line.Substring(0,1)
IF ([byte][char]$FirstCharacter -eq 26) { break }
$ShortObjectType = $line.Substring(0,3).ToUpper()
Switch ($ShortObjectType)
{
"FOR" {$ShortObjectType = 'PAG'}
"DAT" {break}
}
if ($FirstCharacter -ne ' ')
{
Write-Host $line
$ObjectID = $line.Substring(10,10)
$ObjectID = $ObjectID.Trim()
$NewFileName = "$ShortObjectType" + "$ObjectID" +'.TXT'
$ExportPath = $WorkingFolder + $NewFileName
New-Item $ExportPath -ItemType file -force
}
}
}
finally {
$reader.Close()
}
}
else
{Throw 'Please use a Dynamics NAV object file with *.fob extension for this script.'}
}
2. August 2015 23:24
function FobToIndexFilesGridView
{
$FileExists = Test-Path $args
If ($FileExists -eq $False) {Throw "No $args file exists at this location."}
$FileExtension = [System.IO.Path]::GetExtension($args)
if ($FileExtension -eq '.fob')
{
$WorkingFolder = "$env:temp\TEMPINDEX\"
If (Test-Path $WorkingFolder) {Remove-Item $WorkingFolder -Recurse -Force}
$DataArray = New-Object System.Collections.Generic.List[object]
$reader = [System.IO.File]::OpenText($args)
try {
for(;;) {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
$FirstCharacter = $line.Substring(0,1)
IF ([byte][char]$FirstCharacter -eq 26) { break }
$ShortObjectType = $line.Substring(0,3).ToUpper()
Switch ($ShortObjectType)
{
"FOR" {break}
"DAT" {break}
}
if ($FirstCharacter -ne ' ')
{
#Write-Host $line
$ObjectType = $line.Substring(0,9).Trim()
$ObjectID = $line.Substring(10,10).Trim()
$ObjectName = $line.Substring(21,30)
$ObjectDate = $line.Substring(54,10).Trim()
$ObjectTime = $line.Substring(70,8).Trim()
$NewFileName = "$ShortObjectType" + "$ObjectID" +'.TXT'
$ExportPath = $WorkingFolder + $NewFileName
New-Item $ExportPath -ItemType file -force
}
else
{
$ObjectSize = $line.Substring(10,10)
$ObjectVersion = $line.Substring(21,57)
$Obj = New-Object Psobject -Property @{
Type= $ObjectType
ID = $ObjectID
Name = $ObjectName
Date = $ObjectDate
Time = $ObjectTime
Size = $ObjectSize
Version = $ObjectVersion
}
$DataArray.add($Obj)
}
}
}
finally {
$reader.Close()
$DataArray | Out-GridView -title "Fobviewer $args" -wait
}
}
else
{Throw 'Please use a Dynamics NAV object file with *.fob extension for this script.'}
}