@@ -207,7 +207,7 @@ private static ActionResult FilesImmediate(Session session, int elevated, string
207207 try
208208 {
209209 XDocument doc ;
210- using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `File`, `Arguments` FROM `{0}` WHERE `Elevated` = {1}" , tableName , elevated ) ) )
210+ using ( View view = db . OpenView ( string . Format ( "SELECT `Id`, `File`, `Arguments`, `IgnoreErrors` FROM `{0}` WHERE `Elevated` = {1}" , tableName , elevated ) ) )
211211 {
212212 view . Execute ( ) ;
213213
@@ -216,11 +216,12 @@ private static ActionResult FilesImmediate(Session session, int elevated, string
216216 foreach ( Record row in view )
217217 {
218218 var args = session . Format ( row [ "Arguments" ] . ToString ( ) ) ;
219+ var IgnoreErrors = session . Format ( row [ "IgnoreErrors" ] . ToString ( ) ) ;
219220
220221 session . Log ( "args '{0}'" , args ) ;
221222
222223 doc . Root . Add ( new XElement ( "d" , new XAttribute ( "Id" , row [ "Id" ] ) ,
223- new XAttribute ( "file" , session . Format ( row [ "File" ] . ToString ( ) ) ) , new XAttribute ( "args" , args ) ) ) ;
224+ new XAttribute ( "file" , session . Format ( row [ "File" ] . ToString ( ) ) ) , new XAttribute ( "args" , args ) , new XAttribute ( "IgnoreErrors" , IgnoreErrors ) ) ) ;
224225 }
225226 }
226227
@@ -310,15 +311,40 @@ private static ActionResult FilesDeferred(Session session, string deferredProper
310311 string file = row . Attribute ( "file" ) . Value ;
311312
312313 string arguments = row . Attribute ( "args" ) . Value ;
314+ string IgnoreErrors = row . Attribute ( "IgnoreErrors" ) . Value ;
313315
314316 using ( var task = new PowerShellTask ( file , arguments , session ) )
315317 {
316- bool result = task . Execute ( ) ;
317- session . Log ( "PowerShell non-terminating errors: {0}" , ! result ) ;
318- if ( ! result )
318+ try
319319 {
320- session . Log ( "Returning Failure" ) ;
321- return ActionResult . Failure ;
320+ bool result = task . Execute ( ) ;
321+ session . Log ( "PowerShell non-terminating errors: {0}" , ! result ) ;
322+ if ( ! result )
323+ {
324+ if ( ! IgnoreErrors . Equals ( "0" ) )
325+ {
326+ session . Log ( "Ignoring failure due to 'IgnoreErrors' marking" ) ;
327+ }
328+ else
329+ {
330+ session . Log ( "Returning Failure" ) ;
331+ return ActionResult . Failure ;
332+ }
333+ }
334+ }
335+ catch ( Exception ex )
336+ {
337+ if ( ! IgnoreErrors . Equals ( "0" ) )
338+ {
339+ session . Log ( "Ignoring PowerShell error due to 'IgnoreErrors' marking" ) ;
340+ session . Log ( ex . ToString ( ) ) ;
341+ }
342+ else
343+ {
344+ session . Log ( "PowerShell terminating error, returning Failure" ) ;
345+ session . Log ( ex . ToString ( ) ) ;
346+ return ActionResult . Failure ;
347+ }
322348 }
323349 }
324350 }
0 commit comments