header image

Scripting Games commentary: VI Get-Process

Posted by: | April 29, 2011 | No Comment |

One of the events involved getting some information about a file running in a particular process. On a local machine we can use

Get-Process powershell –FileVersionInfo


Get-Process has a computername parameter so we can work remotely. 



If you try this against remote machine

PS> Get-Process powershell -FileVersionInfo -ComputerName server02
Get-Process : Exception getting "Modules" or "FileVersion": "Feature is not supported for remote machines.".
At line:1 char:12
+ Get-Process <<<<  powershell -FileVersionInfo -ComputerName server02
    + CategoryInfo          : InvalidOperation: (System.String[]:String[]) [Get-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.GetProcessCommand


You get an error.

If you look in the help file there is nothing to state that this will happen.

One often overlooked fact is that Get-Help has an online parameter that links to the Microsoft web site.  The PowerShell team update the online help when documentation issues come to light.  if you use

Get-Help Get-Process –Online


You will see that the online help has been updated to reflect the problem with FileVersionInfo

If you want to use it against a remote computer you will need to wrap it in Invoke-Command (best for a one off job) or build a remoting session

Invoke-Command -ScriptBlock {Get-Process powershell -FileVersionInfo} -ComputerName server02

under: PowerShellV2