-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-ABCUpdateLog.ps1
More file actions
67 lines (61 loc) · 2.43 KB
/
Copy pathGet-ABCUpdateLog.ps1
File metadata and controls
67 lines (61 loc) · 2.43 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function Get-AbcUpdateLog {
<#
.SYNOPSIS
Parses the log from a previous ABC-Update action.
.DESCRIPTION
Given a path to a txt file created by the ABC-Update.exe tool,
this function will read the information and create a psobject
on the pipeline. NOTE: The reboot required state is not a
general system status, but a result of the action ABC has taken.
.PARAMETER Path
Path the the log file which contains the output of the ABC-Update.exe command.
#>
[CmdletBinding()]
param (
# Path the the log file which contains the output of the ABC-Update.exe command.
[Parameter(Position=0)]
[string]
$Path = 'C:\Temp\ABC-Update.txt'
)
begin {
$ptnKbNumber = '.+?\|.+?(KB\d{6,11})\s\|'
$ptnRebootRequired = 'Finished\s-\s(.+?)$'
}
process {
if (Test-Path $Path) {
$LogDate = Get-Item $Path | Select-Object -ExpandProperty LastWriteTime
$LogContent = Get-Content $Path
$grpKbNumbers = [regex]::Matches($LogContent,$ptnKbNumber).Groups
$arrKbNumbers = $grpKbNumbers | Foreach-Object {
if ($_.Length -le 12) {$_.Value}
}
$strRebootRequired =
[regex]::Match($LogContent,$ptnRebootRequired).Groups[1].Value
# file://tonyp/c$/TP/Utilities/ABC-Update/ABC-Update.pdf pg.18 Return Codes
$boolRebootRequired =
if ($strRebootRequired -eq 'successful, no reboot required') {
$false
} elseif ($strRebootRequired -eq 'successful, reboot required') {
$true
} elseif ($strRebootRequired -eq 'at least one error occurred, no reboot required') {
$false
} elseif ($strRebootRequired -eq 'at least one error occurred, reboot required') {
$true
} else { # Any other case, no reboots needed
$false
}
# Create the output object
New-Object -TypeName PsObject -Property @{
RebootRequired = $boolRebootRequired
ResultMessage = $strRebootRequired
KB = $arrKbNumbers
LogDate = $LogDate
RawContent = $LogContent -join "`n"
}
} else {
Write-Output 'Log file not found'
}
}
end {
}
}