Submitted By: Kent Finkle

Removes the password when opening an Excel spreadsheet. You must know (and supply) the correct password for this script to work.

PowerShell
Edit|Remove
$comments = @'
Script name: Remove-Password.ps1
Created on: Tuesday, July 03, 2007
Author: Kent Finkle
Purpose: How can I use Windows Powershell to
Remove the Password When Opening an Excel Spreadsheet?
'@
#-----------------------------------------------------
function Release-Ref ($ref) {
([System.Runtime.InteropServices.Marshal]::ReleaseComObject(
[System.__ComObject]$ref) -gt 0)
[System.GC]::Collect()
[System.GC]::WaitForPendingFinalizers() 
}
#-----------------------------------------------------
$xl = new-object -comobject excel.application
 
$xl.Visible = $True

$xl.DisplayAlerts = $False
 
$wb = $xl.Workbooks.Open("C:\Scripts\Test.xls",0,$False,1,"%reTG54w")
 
$wb.Password = ""

$a = $wb.SaveAs( "C:\Scripts\Test.xls")
 
$a = Release-Ref($wb)
$a = Release-Ref($xl)