Skip to content

Commit 61dc54e

Browse files
committed
Get-CommandLine
1 parent 6d646ba commit 61dc54e

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

Modules/Scripts/Get-CommandLine.ps1

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ param (
2323
[switch] $Only,
2424
[switch] $ReturnValue)
2525

26+
if (!$Name)
27+
{
28+
$Only = $false
29+
$ReturnValue = $false
30+
}
31+
2632
$format = '{0,10} {1,-33} {2}'
2733

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+
}
3039

3140
gcim Win32_Process | sort -Property ProcessName | select ProcessId, ProcessName, CommandLine | % `
3241
{
@@ -36,15 +45,17 @@ gcim Win32_Process | sort -Property ProcessName | select ProcessId, ProcessName,
3645
$commandLine = $_.CommandLine
3746
if (!$commandLine) { $commandLine = '' }
3847
$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) + '...' }
4150

42-
if ($name -and ($procnam -like "*$name*" -or $commandLine -like "*$name*"))
51+
if ($Name -and ($procnam -like "*$Name*" -or $commandLine -like "*$Name*"))
4352
{
53+
if ($ReturnValue) { return $_.CommandLine }
54+
4455
Write-Host ($format -f $_.ProcessId, $procnam, $cmd) -ForegroundColor Green
4556
if ($Only) { return }
4657
}
47-
elseif (!$name -and !$Only)
58+
elseif (!$Only -and !$ReturnValue)
4859
{
4960
if ($cmd -and ($cmd -like "*$($env:windir)\System32*"))
5061
{
@@ -58,18 +69,4 @@ gcim Win32_Process | sort -Property ProcessName | select ProcessId, ProcessName,
5869
Write-Host ($format -f $_.ProcessId, $procnam, $cmd)
5970
}
6071
}
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-
}
7572
}

0 commit comments

Comments
 (0)