forked from JohnDuprey/PSWindowsImageRepair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-DISMResult.ps1
78 lines (70 loc) · 2.26 KB
/
Get-DISMResult.ps1
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
67
68
69
70
71
72
73
74
75
76
77
78
function Get-DISMResult {
<#
.SYNOPSIS
Obtain part of the dism results.
.DESCRIPTION
Grab the last 500 lines of the dism log file and if any keywords are applied then filter for those.
.PARAMETER Path
Path to the DISM log file.
.PARAMETER KeyWord
Keyword you wish to look/filter for.
.INPUTS
Description of objects that can be piped to the script.
.OUTPUTS
Description of objects that are output by the script.
.EXAMPLE
Get-DISMResult
.LINK
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/deployment-troubleshooting-and-log-files?view=windows-10#offline-servicing-related-log-files
.NOTES
Detail on what the script does, if this is needed.
#>
[CmdletBinding()]
Param (
# Param1 help description
[Parameter(
Position = 0,
ValueFromPipeline)]
[ValidateScript( {
if (-Not ($_ | Test-Path) ) {
throw "File does not exist"
}
if (-Not ($_ | Test-Path -PathType Leaf) ) {
throw "The Path argument must be a file. Folder paths are not allowed."
}
if ($_ -notmatch "(\.log)") {
throw "The file specified in the path argument must be log"
}
return $true
})]
$Path = "$env:SystemRoot\Logs\DISM\dism.log",
[Parameter(
Position = 1,
ValueFromPipeline)]
[ValidateSet("Success", "Warning", "Fail", "Error", "Finished", "Info")]
$KeyWord
)
begin {
# First block to add/change stuff in
try {
$result = Get-Content -Path $Path -Tail 500
}
catch {
$PSCmdlet.ThrowTerminatingError($PSitem)
}
}
process {
try {
if ($PSBoundParameters.ContainsKey('KeyWord')) {
$result | Select-String $KeyWord
} else {
$result
}
}
catch {
$PSCmdlet.ThrowTerminatingError($PSitem)
}
}
end {
}
}