$ErrorActionPreference = "Stop" $receivePath = "C:\yuji\work\20160312\receive" $inputPath = "C:\yuji\work\20160312\input" $workPath = "C:\yuji\work\20160312\work" $ret = 0 function removeAll($dir){ $private:files = $dir + "\*.*" Remove-Item $files } function unzipAll($dir, $dest){ Get-ChildItem $dir -Filter "*.zip" | ForEach-Object { $private:zip = $shell.NameSpace($_.fullname) $dest.CopyHere($zip.Items()) } } function convertSJISToUTF8($files, $dest){ Get-ChildItem $files | ForEach-Object { $private:file = $_ Invoke-Expression "C:\yuji\work\20160312\iconv.ps1 $file $dest" } } try{ $private:shell = New-Object -ComObject shell.application $private:destPath = $shell.NameSpace($inputPath) removeAll $inputPath unzipAll $receivePath $destPath convertSJISToUTF8 ($inputPath + "\*.txt") $workPath }catch{ Write-host $error $ret = 1 }finally{ } exit $ret