It's calling Get-ParsedSql twice which should be unnecessary - you should be able to just cache the parse result and re-use that for the second one. https://github.com/dfinke/PowerShellNotebook/blob/master/ConvertToSQLNoteBook.ps1#L32 https://github.com/dfinke/PowerShellNotebook/blob/master/ConvertToSQLNoteBook.ps1#L50