mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-26 01:43:37 +01:00
Update check-ps1-file.ps1
This commit is contained in:
parent
8cf0a2372f
commit
ff0c8d2f07
@ -2,7 +2,7 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Checks PowerShell file(s) for validity
|
Checks PowerShell file(s) for validity
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script checks the given PowerShell file(s) for validity.
|
This PowerShell script checks the given PowerShell script file(s) for validity.
|
||||||
.PARAMETER filePattern
|
.PARAMETER filePattern
|
||||||
Specifies the file pattern to the PowerShell file(s)
|
Specifies the file pattern to the PowerShell file(s)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -18,13 +18,13 @@ param([string]$filePattern = "")
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if ($filePattern -eq "" ) { $path = Read-Host "Enter the file pattern to the PowerShell file(s)" }
|
if ($filePattern -eq "" ) { $path = Read-Host "Enter the file pattern to the PowerShell file(s)" }
|
||||||
$files = Get-ChildItem $filePattern
|
|
||||||
|
$files = Get-ChildItem -path "$filePattern" -attributes !Directory
|
||||||
foreach ($file in $files) {
|
foreach ($file in $files) {
|
||||||
$syntaxError = @()
|
$syntaxError = @()
|
||||||
[void][System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$null, [ref]$syntaxError)
|
[void][System.Management.Automation.Language.Parser]::ParseFile($file, [ref]$null, [ref]$syntaxError)
|
||||||
if ("$syntaxError" -ne "") { throw "$syntaxError" }
|
if ("$syntaxError" -ne "") { throw "$syntaxError" }
|
||||||
$basename = (Get-Item "$file").Basename
|
"✔️ Valid PowerShell in $($file.Name)"
|
||||||
"✔️ Valid PowerShell in $basename"
|
|
||||||
}
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user