08-20-2011, 03:48 PM
(This post was last modified: 08-20-2011, 04:59 PM by AceInfinity.)
Hmm... That's not a bad idea, I could put together something like that. I could Pipeline each object instance out and use the System.Diagnostics object with powershell to get the paths.
Here's a quick demo testfile I put together which saves the output of a process list with filepath's to a text file in your C:\ drive called "Output_Proc_List.txt"
Try this:
that will display the top 5 CPU consuming processes with their filepath, for all of them, just remove that loop breaking block of code I have in there.
EDIT: Updated version
** Note: If you use this instead, it will sort each by process name alphabetically after the ordered process numbered list
Here's a quick demo testfile I put together which saves the output of a process list with filepath's to a text file in your C:\ drive called "Output_Proc_List.txt"
Code:
$Process = @{Expression={$_.Name};Label="Process Name";width=25}, `
@{Expression={$_.Path};Label="Filepath"}
$Proc = Get-Process | Format-Table $Process | Out-File -Filepath C:\Output_Proc_List.txt
Try this:
Code:
# Created by Ace - Copyright 2011 TechLifeForum.net
$Proc = Get-Process | Sort-Object CPU -Descending
$Total = 5
$num = 1
write-host
foreach ($objItm in $Proc) {
If ($num -gt $Total) {
break #break the loop
}
write-host "$num) " -foregroundcolor "white" -nonewline; write-host $objItm.ProcessName -foregroundcolor "cyan" -nonewline; write-host " - CPU:"$objItm.CPU
write-host $objItm.Path -foregroundcolor "white"
write-host "# ID:" $objItm.ID -foregroundcolor "white"
write-host
$num += 1
}
write-host
write-host ------------------------------------------------------------------------ -foregroundcolor "cyan"
write-host These are your top $Total CPU consuming processes... -foregroundcolor "cyan"
write-host ------------------------------------------------------------------------ -foregroundcolor "cyan"
write-host
that will display the top 5 CPU consuming processes with their filepath, for all of them, just remove that loop breaking block of code I have in there.
EDIT: Updated version
Code:
# Created by Ace - Copyright 2011 TechLifeForum.net
$Proc = Get-Process | Sort-Object CPU -Descending
$num = 1
write-host
foreach ($objItm in $Proc) {
write-host "$num) " -foregroundcolor "white" -nonewline; write-host $objItm.ProcessName -foregroundcolor "magenta" -nonewline;
If (!($objItm.CPU -eq $null)) {
write-host " - CPU:"$objItm.CPU -foregroundcolor "white"
} else {
write-host " - CPU: " -foregroundcolor "white" -nonewline; write-host "N/A" -foregroundcolor "darkgray"
}
If (!($objItm.Path -eq $null)) {
write-host $objItm.Path -foregroundcolor "cyan"
} else {
write-host "** [No filepath to this process]" -foregroundcolor "darkgray"
}
write-host "# ID:" $objItm.ID -foregroundcolor "white"
write-host
$num += 1
}
write-host
write-host -------------------------------------------------- -foregroundcolor "cyan"
write-host ">" You have ($num - 1) currently running processes... -foregroundcolor "cyan"
write-host -------------------------------------------------- -foregroundcolor "cyan"
write-host
** Note: If you use this instead, it will sort each by process name alphabetically after the ordered process numbered list
Code:
$Proc = Get-Process | Sort-Object ProcessName