Windows Powershell where-object Conditional filtering _powershell

Source: Internet
Author: User
Tags microsoft outlook

Filter pipe Results

Use Get-process to return all the current processes, but you may not be interested in all the processes and then filter through the properties of each process object. The first thing to know is that each object supports those attributes.

Copy Code code as follows:

PS c:powershell> get-process | Select-first 1 | FL *

__nounname:process
Name:acrord32
handles:287
vm:234819584
ws:32616448
pm:63488000
npm:14584
Path:c:program Filesadobereader 10.0readeracrord32
. exe
Company:adobe Systems Incorporated
cpu:96.5334188
fileversion:10.1.2.45
productversion:10.1.2.45
Description:adobe Reader
Product:adobe Reader
id:4820
Priorityclass:normal
handlecount:287
workingset:32616448
pagedmemorysize:63488000
privatememorysize:63488000
virtualmemorysize:234819584
totalprocessortime:00:01:36.5334188
Basepriority:8
ExitCode:
Hasexited:false
Exittime:
handle:3568
MachineName:.
mainwindowhandle:198686
Mainwindowtitle:mastering Powershell-adobe Reader
MainModule:System.Diagnostics.ProcessModule (AcroRd32.exe)
maxworkingset:1413120
minworkingset:204800
Modules: {System.Diagnostics.ProcessModule (AcroRd32.exe),
System.Diagnostics.ProcessModule (Ntdll.dll), Syst
Em. Diagnostics.processmodule (Kernel32.dll), Syste
M.diagnostics.processmodule (KERNELBASE.dll) ...}
nonpagedsystemmemorysize:14584
nonpagedsystemmemorysize64:14584
pagedmemorysize64:63488000
pagedsystemmemorysize:302460
pagedsystemmemorysize64:302460
peakpagedmemorysize:75399168
peakpagedmemorysize64:75399168
peakworkingset:87871488
peakworkingset64:87871488
peakvirtualmemorysize:257703936
peakvirtualmemorysize64:257703936
Priorityboostenabled:true
privatememorysize64:63488000
privilegedprocessortime:00:00:27.7057776
Processname:acrord32
Processoraffinity:3
Responding:true
Sessionid:1
StartInfo:System.Diagnostics.ProcessStartInfo
STARTTIME:2012/1/13 10:25:34
SynchronizingObject:
Threads: {4376, 6636, 8096, 5136 ...}
userprocessortime:00:01:08.8276412
virtualmemorysize64:234819584
Enableraisingevents:false
Standardinput:
StandardOutput:
StandardError:
workingset64:32616448
Site:
Container:

Filters all Notepad processes according to the process name.

Copy Code code as follows:

PS c:powershell> get-process | Where-object {$_. Name-eq "Notepad"}

Handles NPM (k) PM (k) WS (k) VM (M) CPU (s) Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
158 7 8800 37264 114 18.41 6204 Notepad


Filters all IE processes according to the process name.

Copy Code code as follows:

PS c:powershell> get-process | Where-object {$_. Name-eq "IEXPLORE"}

Handles NPM (k) PM (k) WS (k) VM (M) CPU (s) Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
710 12832 18160 175 10.51 4204 IExplore
971 81000 107580 399 22.20 6764 IExplore
336 28516 20096 187 0.34 6792 IExplore
929 51020 46568 10.42 7192 iexplore
835 49200 32360 308 7.82 7952 IExplore

Filter all product publishers to a "Microsoft" process based on company:

Copy Code code as follows:

PS c:powershell> get-process | where-object {$_.company-like ' *microsoft* '}|
Select Name,description,company
Msseces Microsoft Security Clie ... Microsoft Corporation
Notepad Notepad Microsoft Corporation
Onenotem Microsoft OneNote Quick ... Microsoft Corporation
OUTLOOK Microsoft Outlook Microsoft Corporation
PowerShell Windows PowerShell Microsoft Corporation
Prevhost Preview Handler Surroga ... Microsoft Corporation
RDCMan RDCMan Microsoft Corporation
Searchprotocolhost Microsoft Windows Searc ... Microsoft Corporation
TaskHost the host process for the Windows task Microsoft Corporation

Using aliases

Because the use of where-object is higher, so there is a very image of the alias? You can use:

Copy Code code as follows:

PS c:powershell> get-service |? {$_. Name-like "b*"}

Status Name DisplayName
------   ----               -----------
Running bdesvc BitLocker Drive Encryption Service
Running BFE Base Filtering Engine
Running BITS Background Intelligent Transfer Ser ...
Stopped Browser Computer Browser
Stopped Bthserv Bluetooth Support Service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.