dpalecek - 2010-07-02

Hey guys,
I'm currently in the process of converting binary to OpenXML. I've created a Powershell script to assist me in this, in preparation to convert a few thousand files. The only problem I ran into was that once converted, the content is still there, but embedded links aren't given a chance to be updated. (Such as links to other docs) The "Edit Links" option under Office Button>Prepare is no longer there after the conversion. Is there any way to remedy this? Thanks in advance. I've included the Powershell script below:

$path_to_folder="C:\temp"
$ErrorLogFile = New-Item -Path “C:\data” -Name "error_output.txt" -type "FILE" -force
$successLogFile = New-Item -Path “C:\data” -Name "success_output.txt" -type "FILE" -force
foreach ($path in $path_to_folder)
##DOCs##
{
$docs = Get-ChildItem -path $path -recurse -include *.doc
$doc_count = ($docs | measure-object).count
foreach ($doc in $docs)
 {
&'C:\Program Files\DIaLOGIKa\b2xtranslator\doc2x.exe' $doc 
$location = $doc.Directory 
$name = $doc.Name
$newname = $name.replace(".doc",".docx")
$combined = "$location\$newname"
if (Test-Path $combined)
  {    
  add-content $successlogfile -value "$doc was converted succesfully"
  remove-item $doc
  }                                                                                                                                                                                                                                                                                                              
else
  {
 add-content $errorlogfile -value "ALERT: $doc was not converted. Left as .doc file"
  }
 }
##PPT##
$ppts = Get-ChildItem -path $path -recurse -include *.ppt
$ppt_count = ($ppts | measure-object).count
foreach ($ppt in $ppts)
 {
&'C:\Program Files\DIaLOGIKa\b2xtranslator\ppt2x.exe' $ppt 
$location = $ppt.Directory 
$name = $ppt.Name
$newname = $name.replace(".ppt",".pptx")
$combined = "$location\$newname"
if (Test-Path $combined)
  {    
 add-content $successlogfile -value "$ppt was converted succesfully"
 remove-item $ppt
  }                                                                                                                                                                                                                                                                                                              
else
  {
  add-content $errorLogFile -value "ALERT: $ppt was not converted. Left as .ppt file"
  }
 }

##XLS##
$xlss = Get-ChildItem -path $path -recurse -include *.xls
$xls_count = ($xlss | measure-object).count
foreach ($xls in $xlss)
 {
&'C:\Program Files\DIaLOGIKa\b2xtranslator\xls2x.exe' $xls 
$location = $xls.Directory 
$name = $xls.Name
$newname = $name.replace(".xls",".xlsx")
$newname2 = $name.replace(".xls",".xlsm")
$combined2 = "$location\$newname2"
$combined = "$location\$newname"
if (Test-Path $combined)
  {    
     add-content $successlogfile -value "$xls was converted succesfully"
     remove-item $xls
  } 
elseif (Test-Path $combined2)
  {
     add-content $successlogfile -value "$xls was converted succesfully"
     remove-item $xls
  }                                                                                                                                                                                                                                                                                                        
else
 {
  add-content $errorlogfile -value "ALERT: $xls was not converted. Left as .xls file"
 }
}
}
####
  add-content $successlogfile -value "There were $doc_count doc files"
  $docx = Get-ChildItem -path $path -recurse -include *.docx
  $docx_count = ($docx | measure-object).count
  add-content $successlogfile -value "There were $docx_count docx files"
  #####
  add-content $successlogfile -value "There were $ppt_count ppt files"
  $pptx = Get-ChildItem -path $path -recurse -include *.pptx
  $pptx_count = ($pptx | measure-object).count
  add-content $successlogfile -value "There were $pptx_count pptx files"
  #####
  add-content $successlogfile -value "There were $xls_count xls files"
  $xlsx = Get-ChildItem -path $path -recurse -include *.xlsx
  $xlsm = Get-ChildItem -path $path -recurse -include *.xlsm
  $xlsx_count = ($xlsx | measure-object).count
  $xlsm_count = ($xlsm | measure-object).count
  $xls_total = $xlsx_count + $xlsm_count
  add-content $successlogfile -value "There were $xls_total xlsx files"