#RealTime is generally not recommended...(NOTE: One-liner)
gps -p zip.exe | foreach { $_.PriorityClass = "RealTime" }
MSH>[Enum]::getNames("Diagnostics.ProcessPriorityClass")
Normal
Idle
High
RealTime
BelowNormal
AboveNormal
# Apply the process priority only to the first input object(NOTE: One-liner)
gps -processname "process_name" | &{ $input.moveNext(); $input.Current.PriorityClass = "RealTime" }
function set-ProcessPriority {
param($processName = $(throw "Enter process name"), $priority = "Normal")
get-process -processname $processname | foreach { $_.PriorityClass = $priority }
write-host "`"$($processName)`"'s priority is set to `"$($priority)`""
}
# When zip is running
MSH> set-ProcessPriority zip "High"
"zip"'s priority is set to "High"
# When zip operation is over,("Normal" is the default priority level)
MSH set-ProcessPriority zip
"zip"'s priority is set to "Normal"
MSH> gps zip | select name,priorityclass | ft -auto
Name PriorityClass
---- -------------
zip Normal
MSH>get-zipstream .\zipFile.zip | get-zipContent
MSH>get-zipstream .\zipFile.zip | out-zipContent
function Get-ZipStream {
param($zipFileName = $(throw "Enter Zip File Name"))
# Load J# library
# used "out-null" instead of "[void]" since "out-null" would not display
# loaded assembly even if there was an exception thrown
[System.Reflection.Assembly]::LoadWithPartialName("vjslib") | out-null
# 1) Open "java.io.FileInputStream" for a zip file
$fis = new-object java.io.FileInputStream($zipFileName)
# 2) Pipe File Input stream object to "java.io.ZipInputStream"
$zis = new-object java.util.zip.ZipInputStream($fis)
trap {
if ($zis -ne $null) { $zis.close() }
if ($fis -ne $null) { $fis.close() }
break
}
# Return the zip stream
$zis
}
function Get-ZipContent {
if ($args[0] -eq $null) {
# Retrive only the first value
$input.moveNext() | out-null
$zipStream = $input.get_Current()
}
# Load J# library
# used "out-null" instead of "[void]" since "out-null" would not display
# loaded assembly even if there was an exception thrown
[System.Reflection.Assembly]::LoadWithPartialName("vjslib") | out-null
trap { break; }
while (($ze = $zipStream.getNextEntry()) -ne $null) {
$ze.toString()
}
# Close "ZipInputStream" first and then "FileInputStream"
$zipStream.close()
remove-variable zipStream
}
function Out-ZipContent {
if ($args[0] -eq $null) {
$input.MoveNext()
$zis = $input.get_Current()
} else {
$zis = $args[0]
}
trap { break; }
[System.Reflection.Assembly]::LoadWithPartialName("vjslib") | out-null
while (($ze = $zis.getNextEntry()) -ne $null) {
$fn = $ze.getName()
$idx = $fn.LastIndexOf("/")
Write-Host "`$fn = $($fn)"
# we need create a directory
if ($idx -gt 1) {
$dir = $fn.SubString(0, $idx)
$dir = "$((pwd).path)\$($dir)"
# Since the directory doesn't exist, we now create it
if ( !(test-path $dir -type container) ) {
new-item -path $dir -type directory
Write-host "Created $($dir)"
}
}
$file = "$((pwd).path)\$($fn)"
# Write only for leaf files
if ( !(test-path $file -type container) ) {
[sbyte[]]$buf = [sbyte[]](@(0..127) * 8)
$fos = new-object Java.io.fileOutputStream($file)
while ( ($len = $zis.read($buf)) -ge 0 ) {
$fos.Write($buf, 0, $len)
}; $fos.close()
Write-Host "Extracted $($file)"
}
}
}
Experimenting with a different format of blogs...