🗂

PowerShell_7z解凍(備忘録)

2023/01/24に公開

try{
[string]$7zPath = "C:\Users\username\Desktop\試作環境\PowerShell\hashtable\7z"
[string]$decPath = "C:\Users\username\Desktop\試作環境\PowerShell\hashtable\dec"
[string]$7zExe = "C:\Program Files\7-Zip\7z.exe" $7zFileNames = New-Object 'System.Collections.Generic.List[string]'
$decFileNames = New-Object 'System.Collections.Generic.List[string]'
$HashTable = @{}
$7zFileNames = Get-ChildItem -Path $7zPath

foreach ($7zFileName in $7zFileNames) {

	$7zFullName = Join-Path $7zPath $7zFileName Start-Process $7zExe -Verb runas -ArgumentList "x -y -o$decPath $7zFullName"

	#復号後平文マスタファイル名を全て取得
	$decFileNames = Get-ChildItem $decPath

	$i = 0
	foreach ($decFileNameValue in $decFileNames) {
		
		#値がハッシュテーブルに含まれているか確認
		if($HashTable.ContainsValue($decFileNameValue) = $true){

			$7zFileNameKey = -join ($7zFileName, $i)

			#$false=含まれていない為、ハッシュテーブルへ格納 #Key=復号前ファイル名、Value=復号後ファイル名
			$HashTable.add($7zFileNameKey, $decFileNameValue)

			$i++
		}
	}
}

}
catch
{
Write-Output $PSItem.Exception.Message
}

Discussion