Get the process location path using PowerShell

I am trying to get the location of the current process on your computer using PowerShell.

Example

C:\Program Files (x86)\Mozilla Firefox
C:\Windows\sysWOW64\WindowsPowerShell\v1.0
C:\Program Files (x86)\Internet Explorer

When i run the command

$path = Get-Process | Select-Object Path
Split-Path $path

I get the following output, which I do not want. Why is he adding @ {Path = ?

@{Path=C:\Program Files (x86)\Mozilla Firefox
@{Path=C:\Windows\sysWOW64\WindowsPowerShell\v1.0
@{Path=C:\Program Files (x86)\Internet Explorer

When I run Split-Pathas follows, it gives the correct output C:\Windows\sysWOW64\WindowsPowerShell\v1.0.

$pshpath = "C:\Windows\sysWOW64\WindowsPowerShell\v1.0\powershell.exe"
Split-Path $pshpath
+4
source share
2 answers
$path = Get-Process | Select-Object Path

returns an array of objects. Each object in the array will have a Path property along with an optional value.

The "path" parameter for split-path takes "string" arguments, so when you run Split-Path $path

, , -.

split-path , :

 $path | Split-path

, , , :

Get-Process | Select-Object -ExpandProperty Path
+6

, :

ps | % {$_.Path}

:

Get-Process | ForEach-Object {$_.Path}

:

$path = Get-Process | Select-Object Path

, $path:

$path | Get-Member

:

   TypeName: Selected.System.Diagnostics.Process

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
Path        NoteProperty System.String Path=C:\windows\system32\atieclxx.exe

Path String, NoteProperty, , Split-Path.

+1

All Articles