Submitted By: Kent Finkle

Opens an Excel spreadsheet, updates all the Excel type links, and then breaks each of those links.

PowerShell
Edit|Remove
$comments = @' 
Script name: Break-Links.ps1 
Created on: Wednesday, September 12, 2007 
Author: Kent Finkle 
Purpose: How can I use Windows Powershell to 
Update and Then Break All the Links in an Excel Spreadsheet? 
'@ 
# ----------------------------------------------------- 
function Release-Ref ($ref) { 
([System.Runtime.InteropServices.Marshal]::ReleaseComObject( 
[System.__ComObject]$ref) -gt 0) 
[System.GC]::Collect() 
[System.GC]::WaitForPendingFinalizers() 
} 
# ----------------------------------------------------- 
$xlLinkTypeExcelLinks = 1 
$xlExcelLinks = 1 
$xl = new-object -comobject excel.application 
$xl.Visible = $True 
$wb = $xl.Workbooks.Open("C:\Scripts\Test.xls", 3) 
$links = $wb.LinkSources($xlLinkTypeExcelLinks) 
for ($i = 1; $i -le $links.length; $i++) { 
    $a = $wb.BreakLink($links[$i], $xlLinkTypeExcelLinks) 
} 
$a = Release-Ref($wb) 
$a = Release-Ref($xl)