-errorVariable
causes an error message (if the cmdlet fails) to be stored in the specified variable. $error
, the type of the indicated variable is System.Collections.ArrayList
whose elements store System.Management.Automation.ErrorRecord
objects. $item = get-item ` inexisting-item ` -errorVariable err ` -errorAction silentlyContinue if ($err) { write-host $err } else { write-host "item $item found" }