# # Copyright 2008 Josh Erickson (josh dot sonshine at gmail dot com) # # Function unprotectword # # Arguments: # $ori - The file you're wanting to unprotect # $des - The file to save it was when it's all done being unprotected. # # Usage: # unprotected "C:\original.doc" "c:\unprotected.doc"; # # Requirements: # Powershell # Word 2003/2007 (Only tested with Office 2007 with Office 2003 (.doc) files though) # function unprotectword { $ori = $args[0]; $des = $args[1]; $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML"); $a = new-object -comobject word.application $b = $a.documents.open($ori); $b.saveas([ref]"$($env:temp)\temp_word_unprotected.html", [ref]$saveFormat); $b.close(); $a.quit(); $reg = new-object System.Text.RegularExpressions.regex "(.*)"; $res = $reg.replace((gc "$($env:temp)\temp_word_unprotected.html"), ""); #"00000000"); $res = $res.replace("Forms","Forms"); out-file -filepath "$($env:temp)\temp_word_unprotected.html" -inputobject $res; $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); $a = new-object -comobject word.application $b = $a.documents.open("$($env:temp)\temp_word_unprotected.html"); $b.saveas([ref]$des, [ref]$saveFormat); $b.close(); $a.quit(); #([regex]::match($c, "(.*)")).groups[1].value; }