-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample-Read-FileContentFromZip
More file actions
33 lines (25 loc) · 968 Bytes
/
Example-Read-FileContentFromZip
File metadata and controls
33 lines (25 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$zipfile = Get-ChildItem "C:\temp\myzip.zip"
#Open the Zip file for reading
$zipObject = [IO.Compression.ZipFile]::OpenRead("$($zipFile.FullName)")
#finding only xml files
foreach($file in ($zipObject.Entries) | ? {$_.name -match "xml$" } ) {
#Open the file to read the contents
$fileStream = $file.Open()
$reader = New-Object IO.StreamReader($fileStream)
$fileContent = $reader.ReadToEnd()
$reader.Close()
$fileStream.Close()
#Create an output object
$hash = [ordered]@{}
$hash.ZipFileName = $zipFile.Name
$hash.ZipFileFullName = $zipFile.FullName
$hash.Application = $AppDirectory.Name
$hash.ApplicationVersion = $versionDirectory.Name
$hash.XMLFileName = $file.Name
$hash.XMLFileZipPath = $File.FullName
$hash.XMLFileContent = $fileContent
$object = new-object PSObject -property $hash
$object
}#end foreach file in ZipObject
#Close the zip object
$zipObject.Dispose()