Difference between revisions of "Getting Started (PowerShell)"

Jump to navigation Jump to search
Added "PowerShell Process"
(Initial creation - content from depreciated PowerShell page)
 
(Added "PowerShell Process")
Line 103: Line 103:
|-
|-
|<code> $host.UI.RawUI.WindowTitle </code>                              || Command shell title (change at will)
|<code> $host.UI.RawUI.WindowTitle </code>                              || Command shell title (change at will)
|}
== PowerShell Process ==
To get information about the current running PowerShell session process, use...
<source lang="powershell">
$proc = [System.Diagnostics.Process]::GetCurrentProcess()
</source>
...from which you can get all sorts of performance and other metrics such as total CPU time taken, various memory usage metrics and so forth.  Which can be useful if you have a script that you want to run continuously, but you want to be able to monitor that its behaving (no excessive CPU usage or memory leaking).
The object type returned by the above is exactly the same as is returned by <code>[http://technet.microsoft.com/en-us/library/dd347630.aspx Get-Process]</code>.
=== Process Priority ===
In order to change the priority of the current PowerShell process, use...
<source lang="powershell">
( [System.Diagnostics.Process]::GetCurrentProcess() ).PriorityClass = "NewPriority"
</source>
...where NewPriority is any of (though I'd recommend limiting to either BelowNormal or AboveNormal)...
{|class="vwikitable"
|-
! Priority          !! Description
|-
! Idle             
| Only runs when system is idle, which may mean that the process never gets enough execution time to do anything useful.
|-
! BelowNormal
| Ensures that the process will yield to most other processes running on the system (good for background tasks).
|-
! Normal
| Default - recommended for most tasks
|-
! AboveNormal
| Ensures that most other processes running on the system will yield to the PowerShell process (good for urgent, high priority tasks).
|-
! High
| Process will try to run immediately.<br>Can lead to a system having constant high CPU and sluggish overall performance.
|-
! RealTime
| Process overrides all other processes (including system tasks).<br>Can lead to an unresponsive, locked out system unless process has been specifically written to run in RealTime mode, or will only run for a very brief period.
|}
|}


Navigation menu