PowerShell script to extract file from zip-archive
The PowerShell script below extracts one file from zip-archive which contains several files. I use code like this to get files with financial references from zip-archives and update SharePoint lists from them. So there's a lot of things where this sctipt can be used.
Below I write a sctipt with comments. So I don't think it would be difficult to understand the meaning of code.
function ExtractFilesFromZip($zipsource, $filename, $dest) { $FOF_SILENT_FLAG = 4 $FOF_NOCONFIRMATION_FLAG = 16 foreach($item in $zipsource.items()) { If ($item.Name -eq $filename) { $shell.NameSpace($path).copyhere($item, $FOF_SILENT_FLAG + $FOF_NOCONFIRMATION_FLAG) } else { # you can add something for logging or debugging } } } #connect shell.application to work with zipped content $shell = new-object -com shell.application #path where zip-archive is $path = "C:\DataFolder\Work\" #filename of archive $zip_file = "eas_ch03.zip" #name of file for extracting $file_to_extract = "eas029.csv" #read zip content $zip = $shell.NameSpace($path + $zip_file) #execute function ExtractFilesFromZip -zipsource $zip -filename $file_to_extract -dest $path