LoginSignup
3
2

More than 5 years have passed since last update.

powershellでパスワード付きのエクセルのパスワードチェックを行う

Last updated at Posted at 2016-09-04

パスワードがかけられた大量のエクセル遺(資)産を自動処理するときにパスワードが混在していたため作成。つらいw
サブフォルダも含めてパスワードチェックします。

$passwd_str  = $args[0]
$target_path = $args[1]
$error_str=@()

$xlslist=(get-childitem ($target_path+"\*xls*") -Recurse)

foreach($xlspath in $xlslist.fullname){
$xls=New-Object -ComObject excel.application
    try{
        $wbk1=$xls.workbooks.open($xlspath,[Type]::Missing,[Type]::Missing,[Type]::Missing,$passwd_str,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing,[Type]::Missing)
    }catch{
         $error_str+=$xlspath
    }
$xls.quit()
$xls = $null
[gc]::Collect()
}

echo ("【パスワード】" + $passwd_str)
echo ("【ターゲットパス】"+$target_path)
echo ("【開けなかったファイル】")
echo $error_str

下記のように呼び出すと試行したパスワードとエクセル検索したパスのルートと
与えたパスワードで開けなかったエクセルがフルパスで表示されます。

スクリプト名 "hoge" "c:\work\"
【パスワード】hoge
【ターゲットパス】C:\work\
【開けなかったファイル】
C:\work\hoge1.xlsx
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2