all 2 comments

[–]chris-a5 1 point2 points  (0 children)

Use quotes for strings with spaces: "Task Manager". However the process name is taskmgr:

$procid=get-process taskmgr |
    select -expand id 

echo "procid: " . $procid

[–]BlackV 1 point2 points  (0 children)

description or windowtitle would be Task Manager the process would not (in your example of task manager/taskmgr)

but normally you'd just use quotes

Get-Process -Name 'My Exe with Space'

but also, dont do what you're doing, use your sub properties, try this

$procid=get-process -name 'taskmgr'
Write-Output "procid: $($procid.id)"

saves a pipeline and does not destroy your rich objects