Right now runbooks will get uploaded regardless of whether or not they contain code that can be parsed. A call should be added to make sure this doesn't happen. Finding out that the code cannot be parsed while in the portal means waiting for the upload, setting of variables, and runbook queue before an error occurs.
This can be achieved with the following:
$ParseErrors = @()
$FilePath = 'C:\Test\cantparse.ps1'
[System.Management.Automation.Language.Parser]::ParseFile($FilePath, [ref]$null, [ref]$ParseErrors) | Out-Null
if ($ParseErrors) {
$ParseErrors | ForEach-Object -Process {
Write-Error -Message "Failed to parse file '$FilePath': $($_.Message) at line $($_.Extent.StartLineNumber) column $($_.Extent.StartColumnNumber)" -ErrorId $_.ErrorId -ErrorAction Continue
}
return
}
Right now runbooks will get uploaded regardless of whether or not they contain code that can be parsed. A call should be added to make sure this doesn't happen. Finding out that the code cannot be parsed while in the portal means waiting for the upload, setting of variables, and runbook queue before an error occurs.
This can be achieved with the following: