1

Thank you in advance to taking in consideration such stupid query. I am trying to get Process list with some extended properties from powershell with following query:

**Get-Process -FileVersionInfo | select -Unique | Select-Object * | Format-Table -Property OriginalFilename, FileName, InternalName, ProductName, CompanyName, FileVersion -Wrap > C:\Users\user\OneDrive\Desktop\final.txt**

It works but for some processes I am unable to get FileVersion which is ok and I don't care about that. Problem is that Even trying to catch the exception, It simple does nothing.

Get-Process: Cannot enumerate the file version information of the "csrss" process. At line:1 char:7

  • try { Get-Process -FileVersionInfo | select -Unique | Select-Object * ...
  •   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : PermissionDenied: (System.Diagnostics.Process (csrss):Process) [Get-Process], ProcessCommandException
    • FullyQualifiedErrorId : CouldnotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand

Tried to get exception details with

**$Error[0] | Select-Property ***

and

**$Error[0].exception.GetType().fullname**

Which gives following result:

WriteErrorStream : True PSMessageDetails : Exception
: Microsoft.PowerShell.Commands.ProcessCommandException: Cannot enumerate the file version information of the "Idle" process. ---> System.ComponentModel.Win32Exception: Unable to enumerate the process modules. at System.Diagnostics.NtProcessManager.GetModuleInfos(Int32 processId, Boolean firstModuleOnly) at System.Diagnostics.NtProcessManager.GetFirstModuleInfo(Int32 processId) at System.Diagnostics.Process.get_MainModule() at System.Management.Automation.PsUtils.GetMainModule(Process targetProcess) at Microsoft.PowerShell.Commands.GetProcessCommand.ProcessRecord() --- End of inner exception stack trace --- TargetObject : System.Diagnostics.Process (Idle) CategoryInfo : PermissionDenied: (System.Diagnostics.Process (Idle):Process) [Get-Process], ProcessCommandException FullyQualifiedErrorId : CouldnotEnumerateFileVer,Microsoft.PowerShell.Commands.GetProcessCommand ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at , : line 1 PipelineIterationInfo : {0, 1, 64, 0...}

While trying to catch the exception with [Microsoft.PowerShell.Commands.ProcessCommandException] it simply does nothing and still throws bunch on red lines.

try { Get-Process -FileVersionInfo | select -Unique | Select-Object * | Format-Table -Property OriginalFilename, FileName, InternalName, ProductName, CompanyName, FileVersion -Wrap > C:\Users\user\OneDrive\Desktop\final.txt 
} catch [Microsoft.PowerShell.Commands.ProcessCommandException] { 
Write-Verbose "Catch all" -Verbose
}

Could you help please? Thanks in advance.

2
  • Use -ErrorAction Stop in try block! Commented Nov 2, 2021 at 10:14
  • Hi @AbdulNiyasPM , thank for the reply. What do you mean with that? Commented Nov 2, 2021 at 10:19

1 Answer 1

1

You can ignore the processes you don't have the required access to by adding an ErrorAction to Get-Process

Get-Process -FileVersionInfo -ErrorAction Ignore

If you somehow do need to know what processes gave you errors, you can use

Get-Process -FileVersionInfo -ErrorAction SilentlyContinue

and look at $error afterwards or cudo's to @zett42

Get-Process -FileVersionInfo -ErrorAction SilentlyContinue -ErrorVariable ProcError

and look at $ProcError afterwards

Sign up to request clarification or add additional context in comments.

1 Comment

@zett42 - thx, updated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.