2
2
. SYNOPSIS
3
3
Checks all XML files in a directory tree
4
4
. DESCRIPTION
5
- This PowerShell script verifies each XML file (with suffix .xml) in the given directory tree for validity.
5
+ This PowerShell script verifies any XML file (with suffix .xml) in the given directory tree for validity.
6
6
. PARAMETER path
7
7
Specifies the path to the directory tree (current working dir by default)
8
8
. EXAMPLE
9
9
PS> ./check-xml-files.ps1 C:\Windows
10
10
...
11
- ✔️ Checked 3387 XML files within 📂C:\Windows in 174 sec
11
+ ✔️ Checked 3387 XML files (2462 invalid, 925 valid) within 📂C:\Windows in 116 sec
12
12
. LINK
13
13
https://github.com/fleschutz/PowerShell
14
14
. NOTES
@@ -19,19 +19,19 @@ param([string]$path = "$PWD")
19
19
20
20
try {
21
21
$stopWatch = [system.diagnostics.stopwatch ]::startNew()
22
-
23
22
$path = Resolve-Path " $path "
24
- [int ]$numXmlFiles = 0
23
+ Write-Progress " Scanning any XML file within $path ..."
24
+ [int ]$valid = [int ]$invalid = 0
25
25
26
- Write-Progress " Scanning all XML files within $path ..."
27
26
Get-ChildItem - path " $path " - attributes ! Directory - recurse - force | Where-Object { $_.Name -like " *.xml" } | Foreach-Object {
28
27
& $PSScriptRoot / check- xml- file.ps1 " $ ( $_.FullName ) "
29
- $numXmlFiles ++
28
+ if ( $lastExitCode -eq 0 ) { $valid ++ } else { $invalid ++ }
30
29
}
31
30
Write-Progress - completed " Done."
32
31
32
+ [int ]$total = $valid + $invalid
33
33
[int ]$elapsed = $stopWatch.Elapsed.TotalSeconds
34
- " ✔️ Checked $numXmlFiles XML files within 📂$path in $elapsed sec"
34
+ " ✔️ Checked $total XML files ( $invalid invalid, $valid valid) within 📂$path in $elapsed sec"
35
35
exit 0 # success
36
36
} catch {
37
37
" ⚠️ Error in line $ ( $_.InvocationInfo.ScriptLineNumber ) : $ ( $Error [0 ]) "
0 commit comments