all scripts
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
Function ConvertFrom-Gzip
|
||||
{
|
||||
<#
|
||||
.SYNOPSIS
|
||||
This function will decompress the contents of a GZip file and output it to the pipeline. Each line in the converted file is
|
||||
output as distinct object.
|
||||
|
||||
.DESCRIPTION
|
||||
Using the System.IO.GZipstream class this function will decompress a GZip file and send the contents into
|
||||
the pipeline. The output is one System.String object per line. It supports the various types of encoding
|
||||
provided by the System.text.encoding class.
|
||||
|
||||
.EXAMPLE
|
||||
ConvertFrom-Gzip -path c:\test.gz
|
||||
|
||||
test content
|
||||
|
||||
.EXAMPLE
|
||||
get-childitem c:\archive -recure -filter *.gz | convertfrom-Gzip -encoding unicode | select-string -pattern "Routing failed" -simplematch
|
||||
|
||||
Looks through the c:\archive folder for all .gz files, those files are then converted to system.string
|
||||
objects, all that data is piped to select-string. Strings which match the pattern "Routing failed" are returned to the console.
|
||||
|
||||
.EXAMPLE
|
||||
get-item c:\file.txt.gz | convertfrom-Gzip | out-string | out-file c:\file.txt
|
||||
|
||||
Converts c:\file.txt.gz to a string array and then into a single string object. That string object is then written into a new file.
|
||||
|
||||
.NOTES
|
||||
Written by Jason Morgan
|
||||
Created on 1/10/2013
|
||||
Last Modified 7/11/2014
|
||||
# added support for relative paths
|
||||
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
# Enter the path to the target GZip file, *.gz
|
||||
[Parameter(
|
||||
Mandatory = $true,
|
||||
ValueFromPipeline=$True,
|
||||
ValueFromPipelineByPropertyName=$True,
|
||||
HelpMessage="Enter the path to the target GZip file, *.gz",
|
||||
ParameterSetName='Default')]
|
||||
[Alias("Fullname")]
|
||||
[ValidateScript({$_.endswith(".gz")})]
|
||||
[String]$Path,
|
||||
# Specify the type of encoding of the original file, acceptable formats are, "ASCII","Unicode","BigEndianUnicode","Default","UTF32","UTF7","UTF8"
|
||||
[Parameter(Mandatory=$false,
|
||||
ParameterSetName='Default')]
|
||||
[ValidateSet("ASCII","Unicode","BigEndianUnicode","Default","UTF32","UTF7","UTF8")]
|
||||
[String]$Encoding = "ASCII"
|
||||
)
|
||||
Begin
|
||||
{
|
||||
Set-StrictMode -Version Latest
|
||||
Write-Verbose "Create Encoding object"
|
||||
$enc= [System.Text.Encoding]::$encoding
|
||||
}
|
||||
Process
|
||||
{
|
||||
Write-Debug "Beginning process for file at path: $Path"
|
||||
Write-Verbose "test path"
|
||||
if (-not ([system.io.path]::IsPathRooted($path)))
|
||||
{
|
||||
Write-Verbose 'Generating absolute path'
|
||||
Try {$path = (Resolve-Path -Path $Path -ErrorAction Stop).Path} catch {throw 'Failed to resolve path'}
|
||||
Write-Debug "New Path: $Path"
|
||||
}
|
||||
Write-Verbose "Opening file stream for $path"
|
||||
$file = New-Object System.IO.FileStream $path, ([IO.FileMode]::Open), ([IO.FileAccess]::Read), ([IO.FileShare]::Read)
|
||||
Write-Verbose "Create MemoryStream Object, the MemoryStream will hold the decompressed data until it is loaded into `$array"
|
||||
$stream = new-object -TypeName System.IO.MemoryStream
|
||||
Write-Verbose "Construct a new [System.IO.GZipStream] object, created in Decompress mode"
|
||||
$GZipStream = New-object -TypeName System.IO.Compression.GZipStream -ArgumentList $file, ([System.IO.Compression.CompressionMode]::Decompress)
|
||||
Write-Verbose "Open a Buffer that will be used to move the decompressed data from `$GZipStream to `$stream"
|
||||
$buffer = New-Object byte[](1024)
|
||||
Write-Verbose "Instantiate `$count outside of the Do/While loop"
|
||||
$count = 0
|
||||
Write-Verbose "Start Do/While loop, this loop will perform the job of reading decopressed data from the gzipstream object into the MemoryStream object. The Do/While loop continues until `$GZipStream has been emptied of all data, which is when `$count = 0"
|
||||
do
|
||||
{
|
||||
$count = $gzipstream.Read($buffer, 0, 1024)
|
||||
if ($count -gt 0)
|
||||
{
|
||||
$Stream.Write($buffer, 0, $count)
|
||||
}
|
||||
}
|
||||
While ($count -gt 0)
|
||||
Write-Verbose "Take the data from the MemoryStream and convert it to a Byte Array"
|
||||
$array = $stream.ToArray()
|
||||
Write-Verbose "Close the GZipStream object instead of waiting for a garbage collector to perform this function"
|
||||
$GZipStream.Close()
|
||||
Write-Verbose "Close the MemoryStream object instead of waiting for a garbage collector to perform this function"
|
||||
$stream.Close()
|
||||
Write-Verbose "Close the FileStream object instead of waiting for a garbage collector to perform this function"
|
||||
$file.Close()
|
||||
Write-Verbose "Create string(s) from byte array, a split is added after the conversion to ensure each new line character creates a new string"
|
||||
$enc.GetString($array).Split("`n")
|
||||
}
|
||||
End {}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
. .\LogbookScan.ConvertFromGzip.ps1
|
||||
|
||||
# Edit me
|
||||
# Types: RVM, NTX, DC
|
||||
$type = 'NTX'
|
||||
|
||||
# Also edit me
|
||||
$folders = @()
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\14"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\15"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\16"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\17"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\18"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\19"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\20"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\21"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\22"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\23"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\24"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\25"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\26"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\27"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\28"
|
||||
$folders += Get-Item "\\rejk-p-int003\E-Drive\FTP Repository\EW\LogBooks\$type\2017\08\29"
|
||||
|
||||
|
||||
# Don't edit me unless you know what you're doing
|
||||
|
||||
$i = 1
|
||||
foreach($folder in $folders) {
|
||||
Write-Progress -Activity "Folders $($folder.FullName)" -Status "$i of $($folders.Count)" -Id 1 -PercentComplete (100 / $folders.Count * $i)
|
||||
|
||||
# Get all files in current folder
|
||||
$items = Get-ChildItem -Path $folder.FullName
|
||||
|
||||
$y = 1
|
||||
$result = foreach($item in $items) {
|
||||
try {
|
||||
Write-Progress -Activity 'Files' -Status "$y of $($items.Count)" -ParentId 1 -PercentComplete (100 / $items.Count * $y)
|
||||
|
||||
# Unpack gzip and get logbook file
|
||||
$file = $item.FullName | ConvertFrom-Gzip
|
||||
|
||||
|
||||
if($type -eq 'RVM') {
|
||||
$file | Select-String -Pattern 'Ticket processing operation error;.*?;29'
|
||||
}
|
||||
elseif($type -eq 'NTX') {
|
||||
$file | Select-String -Pattern 'Error type : 120'
|
||||
}
|
||||
elseif($type -eq 'DC') {
|
||||
throw "Type $type not implemented"
|
||||
}
|
||||
else {
|
||||
Write-Warning "Unknown type $type"
|
||||
break
|
||||
}
|
||||
|
||||
$file = $null
|
||||
$y++
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Failed to process $($item.FullName): $_"
|
||||
}
|
||||
}
|
||||
|
||||
$result | Out-File -Append -FilePath "errortype29$type.csv"
|
||||
|
||||
$result = $null
|
||||
|
||||
[System.GC]::Collect()
|
||||
"Last folder operated on: $i : $($folder.FullName)" | Out-File -FilePath "errortype29$type.count" -Append
|
||||
|
||||
$i++
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($type -eq 'NTX') {
|
||||
$csv = Import-Csv .\errortype29NTX.csv -Delimiter ';' -Header 'Date','Time','DeviceType','DeviceId','Unknown1','Unknown2','ErrorDescription','TransactionType','MediaSerialNumber','ErrorType'
|
||||
$csv | where { $_.ErrorType -eq 'Error type : 120' } | % { ($_.MediaserialNumber -split ' : ')[1] } | sort -Unique > ntx.txt
|
||||
|
||||
#SELECT omi.CardEngravedID FROM trk.ObjMediaInstance omi with(nolock)
|
||||
#WHERE omi.MediaSerialNumberID IN ( ... )
|
||||
}
|
||||
elseif($type -eq 'RVM') {
|
||||
$csv = Import-Csv .\errortype29RVM.csv -Delimiter ';' -Header 'Date','Time','DeviceType','DeviceId','Unknown1','Unknown2','ErrorDescription','MediaSerialNumber','ErrorType'
|
||||
$csv | where { $_.ErrorType -eq '120' } | % { $_.MediaSerialNumber } | sort -Unique | % { $_ -replace '308430','' } | % { $_ -replace ' ','' } > rvm.txt
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Binary file not shown.
Binary file not shown.
|
Can't render this file because it is too large.
|
Reference in New Issue
Block a user