Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- $pathbefore = 'C:\$Windows.~BT\Sources\Panther\setupact.log',
- $pathafter = "C:\WINDOWS\Panther\setupact.log",
- $dl = '[/PreDownload /Package /Quiet',
- $dlcomplete = "/install",
- $inst = '[/install',
- $reboot = 'Action Progress: [100%]',
- $finished = 'SetupPlatform: Phase "OOBEBoot" completed successfully.'
- )
- $header = "Date","x","Messagetype","Modul","Message"
- #DL startet = ok
- #DL finish = no pattern found except installation is starting
- #IS startet = ok
- #first reboot =
- #inst finish = ok
- ### LOGFILE NACH UPDATE ABFRAGEN
- #DOWNLOAD STARTED
- #TEST IF WE ARE BERFORE OR AFTER THE UPDATE AND PARSE CORRECT LOGFILE
- if (Test-Path $pathbefore){
- #Parse Logfile from $pathbefore, replace the first 3x spaces with comma and look for pattern $dl, because of special character we use -SimpleMatch, we convert as csv to get separate attributes with own header and we want only the first value retunred
- $time1 = (get-content $pathbefore) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $dl -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- #Separating the resulting line into different parts by spaces (from 1 to all spaces between) and skipping the first value containing path, filename, linenumber and date
- if($time1){$time1a = Get-Date -Date $time1.date}
- #Returns found time from logfile and removes the following comma
- Write-Host -ForegroundColor Gray "Download was started at $time1a"
- }
- else{
- $time1 = (get-content $pathafter) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $dl -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- if($time1){$time1a = Get-Date -Date $time1.date}
- Write-Host -ForegroundColor Gray "Download was started at $time1a"
- }
- #DOWNLOAD FINISHED
- if (Test-Path $pathbefore){
- $time2 = (get-content $pathbefore) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $dlcomplete -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- $time2a = Get-Date -Date $time2.date
- Write-Host -ForegroundColor Gray "Download was completed at $time2a"
- }
- else{
- $time2 = (get-content $pathafter) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $dlcomplete -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- $time2a = Get-Date -Date $time2.date
- Write-Host -ForegroundColor Gray "Download was completed at $time2a"
- }
- #INSTALLATIONS STARTED
- if (Test-Path $pathbefore){
- $time3 = (get-content $pathbefore) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $inst -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- $time3a = Get-Date -Date $time3.date
- Write-Host -ForegroundColor Cyan "Installation was startet at $time3a"
- }
- else{
- $time3 = (get-content $pathafter) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $inst -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -First 1
- $time3a = Get-Date -Date $time3.date
- Write-Host -ForegroundColor Cyan "Installation was startet at $time3a"
- }
- #FIRST REBOOT
- if (Test-Path $pathbefore){
- $time4 = (get-content $pathbefore) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $reboot -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -Last 1
- $time4a = Get-Date -Date $time4.date
- Write-Host -ForegroundColor Cyan "First reboot was initiated at $time4a"
- }
- else{
- $time4 = (get-content $pathafter) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $reboot -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -Last 1
- $time4a = Get-Date -Date $time4.date
- Write-Host -ForegroundColor Cyan "First reboot was initiated at $time4a"
- }
- #INSTALLATION FINISHED, LOGFILE LOCATION BEFORE IS NOT NEEDED ANYMORE
- $time5 = (get-content $pathafter) -replace '^(\S+?) (\S+?) (\S+?) (.*)','$1 $2,$3,$4' | select-string -pattern $finished -SimpleMatch –allmatches | Convertfrom-csv -Delimiter "," -header $header | Select-Object -Last 1
- $time5a = Get-Date -Date $time5.date
- Write-Host -ForegroundColor Green "Installation was finished at $time5a"
- #SPACES BETWEEN TiMES AND CALCULTIONS
- Write-Host " "
- Write-Host " "
- #CAlCULATE TIMES
- #CALCULATE DOWNLOADTIME
- # IF time1a has a value, calculate time and report to user
- if ($time1a){
- $download = $time2a - $time1a
- Write-Host -ForegroundColor Gray "Download =" $download
- }
- else
- {
- Write-Host -ForegroundColor Gray "No download detected"
- }
- #CALCUALTE INSTALLATIONTIME
- $installation = $time5a - $time3a
- Write-Host -ForegroundColor Cyan "Installation =" $installation | select hours, minutes
- #CALCULATE TOTALTIME IF POSSIBLE
- if ($time1a ){
- $total = $time5a - $time1a
- Write-Host -ForegroundColor Green "Total =" $total | select hours, minutes
- }
- else{
- Write-Host -ForegroundColor Green "total time can't be calculated"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement