File tree Expand file tree Collapse file tree 2 files changed +14
-16
lines changed Expand file tree Collapse file tree 2 files changed +14
-16
lines changed Original file line number Diff line number Diff line change 1
1
<#
2
2
. SYNOPSIS
3
- Verifies the given XML file
3
+ Verifies an XML file
4
4
. DESCRIPTION
5
5
This PowerShell script checks the given XML file for validity.
6
6
. PARAMETER path
7
- Specifies the path to the XML file to check
7
+ Specifies the path to the XML file
8
8
. EXAMPLE
9
9
PS> ./check-xml-file.ps1 myfile.xml
10
- ✔️ Valid XML in ' myfile.xml'
10
+ ✔️ Valid XML in 📄 myfile.xml
11
11
. LINK
12
12
https://github.com/fleschutz/PowerShell
13
13
. NOTES
@@ -31,13 +31,11 @@ try {
31
31
while ($Reader.Read ()) { }
32
32
$Reader.Close ()
33
33
34
- if ($script :ErrorCount -gt 0 ) {
35
- throw " Invalid XML in '$path '"
36
- }
34
+ if ($script :ErrorCount -gt 0 ) { throw " Invalid XML" }
37
35
38
- " ✔️ Valid XML in ' $path ' "
36
+ " ✔️ Valid XML in 📄 $path "
39
37
exit 0 # success
40
38
} catch {
41
- " ⚠️ Error in line $ ( $_ .InvocationInfo.ScriptLineNumber ) : $ ( $ Error [0 ]) "
39
+ " ⚠️ $ ( $Error [0 ]) in 📄 $path "
42
40
exit 1
43
41
}
Original file line number Diff line number Diff line change 1
1
<#
2
2
. SYNOPSIS
3
- Checks XML files in a directory tree
3
+ Checks all XML files in a directory tree
4
4
. DESCRIPTION
5
- This PowerShell script verifies each XML file in the given directory tree for validity.
5
+ This PowerShell script verifies each 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 3607 XML files within C:\Windows in 174 sec
11
+ ✔️ Checked 3387 XML files within 📂 C:\Windows in 174 sec
12
12
. LINK
13
13
https://github.com/fleschutz/PowerShell
14
14
. NOTES
@@ -21,17 +21,17 @@ try {
21
21
$stopWatch = [system.diagnostics.stopwatch ]::startNew()
22
22
23
23
$path = Resolve-Path " $path "
24
- [int ]$count = 0
24
+ [int ]$numXmlFiles = 0
25
25
26
- Write-Progress " Checking all *.xml files under $path ..."
27
- Get-ChildItem - path " $path " - attributes ! Directory - recurse - force | Where-Object { $_.Name -like " *.xml* " } | Foreach-Object {
26
+ Write-Progress " Scanning all XML files within $path ..."
27
+ Get-ChildItem - path " $path " - attributes ! Directory - recurse - force | Where-Object { $_.Name -like " *.xml" } | Foreach-Object {
28
28
& $PSScriptRoot / check- xml- file.ps1 " $ ( $_.FullName ) "
29
- $count ++
29
+ $numXmlFiles ++
30
30
}
31
31
Write-Progress - completed " Done."
32
32
33
33
[int ]$elapsed = $stopWatch.Elapsed.TotalSeconds
34
- " ✔️ Checked $count XML files within $path in $elapsed sec"
34
+ " ✔️ Checked $numXmlFiles XML files within 📂 $path in $elapsed sec"
35
35
exit 0 # success
36
36
} catch {
37
37
" ⚠️ Error in line $ ( $_.InvocationInfo.ScriptLineNumber ) : $ ( $Error [0 ]) "
You can’t perform that action at this time.
0 commit comments