Search code examples
powershellwindow

Powershell ScriptProperty to check Path


Please can some one explain how to use Powershell ScriptProperty.

I've checked few tutorials but got information about the -property only. I am trying to check via powershell Process Path.

So am checking get-process | get-member And I got a lot of MemberTypes: Method, Property, NoteProperty, ScriptProperty

But I can't figure out how to use ScriptProperty.

Trying to : Get-Process -Name bits| get-member -membertype scriptproperty | select-object scriptproperty Path But I getting this error:

    Select-Object : A positional parameter cannot be found that accepts argument 'Path'.
At line:1 char:65
+ Get-Process -Name bits| get-member -membertype scriptproperty | select-object sc ...
+                                                                 ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

Example:(sorry for my english) Want to try define path for notepad++ process, I am trying to check path for process, for example if you using notepad++ and if i will try to use that command: Get-Process -Name notepad++| get-member -membertype scriptproperty | Where-Object Name -eq Path and it not providing the process path, only such output :

       TypeName: System.Diagnostics.Process

Name MemberType     Definition
---- ----------     ----------
Path ScriptProperty System.Object Path {get=$this.Mainmodule.FileName;}

How should i use the scriptproperty command to get process path? (I really do not understand)


Solution

  • You want to select the ScriptProperty where the the Name equals Path. So you are looking for the Where-Object cmdlet:

    Get-Process -Name bits | get-member -membertype scriptproperty  | Where-Object Name -eq Path
    

    But beside that, what do you want to? I feel like you don't need the Get-Member cmdlet here...

    Answer to your comment: You want to retrieve the Path of a process, so you don't need to hassle with a ScriptProperty, just select it:

    Get-Process -Name bits | Select Path