Processes

When you want a nice list of processes that consume the most cpu time on your pc type:

get-process | Sort-Object TotalProcessorTime -descending | format-table TotalProcessorTime, name, ID -auto

When you look at the output of get-process you will see an output that displays CPU(s). That is the total time in seconds that it uses the processor. Now let's say you want to see the processes that have consumed more than 1 minute of time in the processor since you started your pc
Get-Process | where {$_.TotalProcessorTime -gt "00:01:00"}

To view all processes and the time they have been running type:
Get-Process| sort starttime  -ErrorAction silentlycontinue | format-table –auto -property name, starttime, @{name="CPU"; expression={("{0,10:n1}" -f $_.cpu)}}

When you want to view multiple servers and see the automatically running services and there status you would type:
$servers= (get-content -Path "\\servername\homedrive\Name\scripts\servers.txt" )
foreach ($name in $servers) {
$name
gwmi win32_service -computername $name -filter "StartMode ='Auto'" | Select-Object Name, Status, State, Startmode
}

When you want only to see the services that are set automatically and are stopped stopping or starting you would type:
$servers= (get-content -Path "\\servername\homedrives\user\pathToFile\servers.txt" )
foreach ($name in $servers) {
$name 
Get-WmiObject win32_service -computername $name -filter "StartMode ='Auto'" -ErrorAction silentlycontinue | Where-Object {$_.State -eq "Stopped" -OR $_.State -eq "Stopping" -OR $_.State -eq "Starting"} | Select-Object Name, Status, State, Startmode | Format-Table -auto
}

When you want to know what the process is doing at this moment I wrote a little script that can/may be altered as desired:
$handle = (Get-Process processname).handle
$process = Get-CimInstance win32_thread -filter "handle = $handle"
$process = ((Get-CimInstance win32_thread -filter "handle = $handle").ThreadWaitReason).ToString()

switch ($process)
    {
    0 {"Executive, The thread is waiting for the scheduler."}
    1 {"FreePage, The thread is waiting for a free virtual memory page."}
    2 {"PageIn, The thread is waiting for a virtual memory page to arrive in memory."}
    3 {"PoolAllocation."}
    4 {"ExecutionDelay, Thread execution is delayed."}
    5 {"FreePage, The thread is waiting for a free virtual memory page."}
    6 {"PageIn, The thread is waiting for a virtual memory page to arrive in memory."}
    7 {"Executive, The thread is waiting for the scheduler."}
    8 {"FreePage, The thread is waiting for a free virtual memory page."}
    9 {"PageIn, The thread is waiting for a virtual memory page to arrive in memory."}
    10 {"PoolAllocation, "}
    11 {"ExecutionDelay, Thread execution is delayed."}
    12 {"FreePage, The thread is waiting for a free virtual memory page."}
    13 {"PageIn, The thread is waiting for a virtual memory page to arrive in memory."}
    14 {"EventPairHigh, The thread is waiting for event pair high."}
    15 {"EventPairLow, The thread is waiting for event pair low."}
    16 {"LPCReceive, The thread is waiting for a local procedure call to arrive."}
    17 {"LPCReply, The thread is waiting for reply to a local procedure call to arrive."}
    18 {"VirtualMemory, The thread is waiting for the system to allocate virtual memory."}
    19 {"PageOut, The thread is waiting for a virtual memory page to be written to disk."}
    20 {"Unknown, The thread is waiting for an unknown reason."}
    }

On Me

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License