Backtrack:  
 
by lunarg on October 12th 2016, at 15:46

I found this little snippet online that allows you to preparse your Powershell scripts to ensure there are no syntax errors in it. This is useful if you need to know the script is error-free but are otherwise unable to run it.

Source: https://rkeithhill.wordpress.com/2007/10/30/powershell-quicktip-preparsing-scripts-to-check-for-syntax-errors/

# Contents of file TestScript.ps1
param($path, [switch]$verbose)

if ($verbose) {
    $VerbosePreference = ‘Continue’
}

trap { Write-Warning $_; $false; continue }
& `
{
    $contents = get-content $path
    $contents = [string]::Join([Environment]::NewLine, $contents)
    [void]$ExecutionContext.InvokeCommand.NewScriptBlock($contents)
    Write-Verbose "Parsed without errors"
    $true
} 
 
 
« February 2025»
SunMonTueWedThuFriSat
      1
2345678
9101112131415
16171819202122
232425262728
 
Links
 
Quote
« When a bird does poo poo in your eye, be happy elephants don't fly. »