# reuse the session for as many queries as you like $sh = Get-CimInstance-ClassName Win32_Share -CimSession$session-Filter'Name="Admin$"' $se = Get-CimInstance-ClassName Win32_Service -CimSession$session
# remove the session at the end Remove-CimSession-CimSession$session
try { # this raises an error Get-Service-Name NonExisting -ErrorAction Stop } catch { # pipe the errorrecord object through the new function # to retrieve all relevant error information # which you then could use to do error logging, or output # custom error messages $_ | ConvertFrom-ErrorRecord