Converting VBScript's Clear Method

Definition: Clears all property settings of the Err object.

Clear

The VBScript Err object keeps track of only the last error that occurred; in contrast, and by default, Windows PowerShell keeps track of the last 256 errors that occurred. Among other things, that changes the definition of “clearing” an error in Windows PowerShell. If you want to mimic VBScript, you can clear the last error - and only the last error - by setting the last error to an empty string (the zero in square brackets represents the last error in the collection):

$error[0] = ""

Alternatively, you can clear out the entire error collection by using the Clear() method:

$error.clear()

Return to the VBScript to Windows PowerShell home page