@@ -23,10 +23,19 @@ param (
23
23
[switch ] $Only ,
24
24
[switch ] $ReturnValue )
25
25
26
+ if (! $Name )
27
+ {
28
+ $Only = $false
29
+ $ReturnValue = $false
30
+ }
31
+
26
32
$format = ' {0,10} {1,-33} {2}'
27
33
28
- Write-Host ($format -f ' processid' , ' ProcessName' , ' CommandLine' )
29
- Write-Host ($format -f ' ---------' , ' -----------' , ' -----------' )
34
+ if (! $ReturnValue )
35
+ {
36
+ Write-Host ($format -f ' processid' , ' ProcessName' , ' CommandLine' )
37
+ Write-Host ($format -f ' ---------' , ' -----------' , ' -----------' )
38
+ }
30
39
31
40
gcim Win32_Process | sort - Property ProcessName | select ProcessId, ProcessName, CommandLine | % `
32
41
{
@@ -36,15 +45,17 @@ gcim Win32_Process | sort -Property ProcessName | select ProcessId, ProcessName,
36
45
$commandLine = $_.CommandLine
37
46
if (! $commandLine ) { $commandLine = ' ' }
38
47
$cmd = $commandLine
39
- $max = $host.UI.RawUI.WindowSize.Width - 44
40
- if ($cmd.Length -gt $max ) { $cmd = $cmd.Substring (0 , $max - 4 ) + ' ...' }
48
+ $max = $host.UI.RawUI.WindowSize.Width - 45
49
+ if ($cmd.Length -gt $max ) { $cmd = $cmd.Substring (0 , $max - 3 ) + ' ...' }
41
50
42
- if ($name -and ($procnam -like " *$name *" -or $commandLine -like " *$name *" ))
51
+ if ($Name -and ($procnam -like " *$Name *" -or $commandLine -like " *$Name *" ))
43
52
{
53
+ if ($ReturnValue ) { return $_.CommandLine }
54
+
44
55
Write-Host ($format -f $_.ProcessId , $procnam , $cmd ) - ForegroundColor Green
45
56
if ($Only ) { return }
46
57
}
47
- elseif (! $name -and ! $Only )
58
+ elseif (! $Only -and ! $ReturnValue )
48
59
{
49
60
if ($cmd -and ($cmd -like " *$ ( $env: windir ) \System32*" ))
50
61
{
@@ -58,18 +69,4 @@ gcim Win32_Process | sort -Property ProcessName | select ProcessId, ProcessName,
58
69
Write-Host ($format -f $_.ProcessId , $procnam , $cmd )
59
70
}
60
71
}
61
- elseif (! $Only )
62
- {
63
- if ($cmd -and ($cmd -like " *$ ( $env: windir ) \System32*" ))
64
- {
65
- if ($ShowSystem )
66
- {
67
- Write-Host ($format -f $_.ProcessId , $procnam , $cmd ) - ForegroundColor DarkGray
68
- }
69
- }
70
- else
71
- {
72
- Write-Host ($format -f $_.ProcessId , $procnam , $cmd )
73
- }
74
- }
75
72
}
0 commit comments