Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
added Test-PsOneScript
  • Loading branch information
TobiasPSP committed Nov 30, 2019
1 parent acf2fee commit 97c67e9
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 0 deletions.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions PSOneTools/1.3/Test-PSOneScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@


function Test-PSOneScript
{
<#
.SYNOPSIS
Parses a PowerShell Script (*.ps1, *.psm1, *.psd1)
.DESCRIPTION
Invokes the simple PSParser and returns tokens and syntax errors
.EXAMPLE
Test-PSOneScript -Path c:\test.ps1
Parses the content of c:\test.ps1 and returns tokens and syntax errors
.EXAMPLE
Get-ChildItem -Path $home -Recurse -Include *.ps1,*.psm1,*.psd1 -File |
Test-PSOneScript |
Out-GridView
parses all PowerShell files found anywhere in your user profile
.EXAMPLE
Get-ChildItem -Path $home -Recurse -Include *.ps1,*.psm1,*.psd1 -File |
Test-PSOneScript |
Where-Object Errors
parses all PowerShell files found anywhere in your user profile
and returns only those files that contain syntax errors
.LINK
https://powershell.one
#>


param
(
# Path to PowerShell script file
# can be a string or any object that has a "Path"
# or "FullName" property:
[String]
[Parameter(Mandatory,ValueFromPipeline)]
[Alias('FullName')]
$Path
)

begin
{
$errors = $null
}
process
{
# create a variable to receive syntax errors:
$errors = $null
# tokenize PowerShell code:
$code = Get-Content -Path $Path -Raw -Encoding Default

# return the results as a custom object
[PSCustomObject]@{
Name = Split-Path -Path $Path -Leaf
Path = $Path
Tokens = [Management.Automation.PSParser]::Tokenize($code, [ref]$errors)
Errors = $errors | Select-Object -ExpandProperty Token -Property Message
}
}
}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions PSOneTools/1.2/module.psm1 → PSOneTools/1.3/module.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
. $PSScriptRoot\Test-PSOnePing.ps1
. $PSScriptRoot\Foreach-ObjectFast.ps1
. $PSScriptRoot\Where-ObjectFast.ps1
. $PSScriptRoot\Test-PSOneScript.ps1

0 comments on commit 97c67e9

Please sign in to comment.