문제

Seems like this should be simple, but powershell is winning another battle with me. Simply wanting to output the name of all the services running on a system, and their executable path, and pipe that into something I can use to search through it like Less.

So far I have:

$services = get-WmiObject -query 'select * from win32_service'
foreach($service in $services){$service.Name $service.Pathname} | less

But thats giving me the "An empty pipe element is not allowed." that I seem to have come up alot. Anyone tell me how to fix this, either by outputting to a file and Ill go through it with vim, or pipe to page/less/etc so I can do quick scan (with my eyes not programically quite yet).

도움이 되었습니까?

해결책

Try doing the following

$services | %{ $_.Pathname } | less

EDIT Add multiple to the path

$services | %{ "{0} {1}" -f $_.Pathname,$_.Name } | less

다른 팁

If you are using PowerShell 2.0, you might like this:

gwmi win32_service | select-object Name,PathName | ogv

ogv (Output-GridView) is a new cmdlet in 2.0.

k=len(x)-1

while(True):
    if x[k]!='0':
        x[k]-=1
        break
    else:
        x[k]='9'
        k--
.

나는 당신이 운동하기 위해 경계 조건을 떠나고 있습니다.

Looks like a good reason to use foreach-object:

$services = get-WmiObject -query 'select * from win32_service'
$services|ForEach-Object {$_|Select-Object Name,Pathname}|less

Please excuse me while I oneline it:

get-WmiObject -query 'select * from win32_service' |ForEach-Object {$_|Select-Object Name,Pathname}|less

foreach-object will return an object to the pipeline based on the input object.

I'm assuming less is an alias of your own making since I don't seem to have it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top