实例:排序、筛选、选择区间:Sort-Object

筛选域组前面 5 位

其中包含表头

Get-ADGroupMember -Identity 创意中心 | Sort-Object | ft name | Select -First 5

name
----
何星星
何娇娇
陈筱筱

筛选域组后面 5 位

其中包含表头

Get-ADGroupMember -Identity 创意中心 | Sort-Object -Descending | ft name | select -First 5

name
----
李小婕
朱小微
钟小杉

获取占用 CPU 最大的 5 个进程

Get-Process | Sort-Object -Descending CPU | Select -First 5

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    685      32    72004    8483832  26,057.84  13016   1 vmware-vmx
   2097     249   670636     844940   8,050.38   3484   1 WXWork
   2458     105    78372     305364     497.53  10624   1 explorer
   1234     149   162972     276716     367.50   5676   1 WeChat
    418      48    46788      87628     157.70  12664   1 WXWorkWeb

获取系统服务并过滤在运行的对象

Where-Object 的参数是布尔表达式,$_代表过滤过程中经过管道的当前结果。

Get-Service | Where-Object {$_.Status -eq "Running"}

Status   Name               DisplayName
------   ----               -----------
Running  Appinfo            Application Information
Running  BFE                Base Filtering Engine
Running  BrokerInfrastru... Background Tasks Infrastructure Ser...
Running  camsvc             功能访问管理器服务
Running  cbdhsvc_161fc1     剪贴板用户服务_161fc1
Running  CDPSvc             连接设备平台服务
Running  CDPUserSvc_161fc1  连接设备平台用户服务_161fc1
Running  CoreMessagingRe... CoreMessaging
Running  CryptSvc           Cryptographic Services
Running  DcomLaunch         DCOM Server Process Launcher
Running  Dfs                DFS Namespace
Running  DFSR               DFS Replication
Running  Dhcp               DHCP Client
Running  DiagTrack          Connected User Experiences and Tele...
Running  DispBrokerDeskt... 显示策略服务
Running  Dnscache           DNS Client
Running  DoSvc              Delivery Optimization
Running  DPS                Diagnostic Policy Service
Running  DsmSvc             Device Setup Manager
Running  DsSvc              Data Sharing Service
Running  EventLog           Windows Event Log
Running  EventSystem        COM+ Event System
Running  Everything         Everything
Running  FlexNet Licensi... FlexNet Licensing Service
Running  FontCache          Windows Font Cache Service
Running  gpsvc              Group Policy Client
Running  hidserv            Human Interface Device Service
Running  iphlpsvc           IP Helper
Running  KeyIso             CNG Key Isolation
Running  LanmanServer       Server
Running  LanmanWorkstation  Workstation
Running  LicenseManager     Windows 许可证管理器服务
Running  LSM                Local Session Manager
Running  mpssvc             Windows Defender Firewall
Running  MSDTC              Distributed Transaction Coordinator
Running  NcbService         Network Connection Broker
Running  Netlogon           Netlogon
Running  Netman             Network Connections
Running  netprofm           Network List Service
Running  NlaSvc             Network Location Awareness
Running  nsi                Network Store Interface Service
Running  PcaSvc             Program Compatibility Assistant Ser...
Running  phpStudySrv        phpstudy 服务
Running  PimIndexMainten... Contact Data_161fc1
Running  PlugPlay           Plug and Play
Running  Power              Power
Running  ProfSvc            User Profile Service
Running  RasMan             Remote Access Connection Manager
Running  RpcEptMapper       RPC Endpoint Mapper
Running  RpcSs              Remote Procedure Call (RPC)
Running  SamSs              Security Accounts Manager
Running  Schedule           Task Scheduler
Running  seclogon           Secondary Logon
Running  SecurityHealthS... Windows 安全中心服务
Running  SENS               System Event Notification Service
Running  ShellHWDetection   Shell Hardware Detection
Running  Spooler            Print Spooler
Running  sppsvc             Software Protection
Running  SstpSvc            Secure Socket Tunneling Protocol Se...
Running  StateRepository    State Repository Service
Running  StorSvc            Storage Service
Running  SunloginService    SunloginService
Running  SysMain            SysMain
Running  SystemEventsBroker System Events Broker
Running  TabletInputService Touch Keyboard and Handwriting Pane...
Running  Themes             Themes
Running  TimeBrokerSvc      Time Broker
Running  TokenBroker        Web 帐户管理器
Running  TrkWks             Distributed Link Tracking Client
Running  UALSVC             User Access Logging Service
Running  UnistoreSvc_161fc1 User Data Storage_161fc1
Running  UserDataSvc_161fc1 User Data Access_161fc1
Running  UserManager        User Manager
Running  UsoSvc             更新 Orchestrator 服务
Running  VaultSvc           Credential Manager
Running  vds                Virtual Disk
Running  VMAuthdService     VMware Authorization Service
Running  VMnetDHCP          VMware DHCP Service
Running  VMUSBArbService    VMware USB Arbitration Service
Running  VMware NAT Service VMware NAT Service
Running  W32Time            Windows Time
Running  Wcmsvc             Windows Connection Manager
Running  WdiServiceHost     Diagnostic Service Host
Running  WdNisSvc           Microsoft Defender Antivirus Networ...
Running  WinDefend          Microsoft Defender Antivirus Service
Running  WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se...
Running  Winmgmt            Windows Management Instrumentation
Running  WinRM              Windows Remote Management (WS-Manag...
Running  WnServiceV1        WnService
Running  WpnService         Windows 推送通知系统服务
Running  WpnUserService_... Windows Push Notifications User Ser...
Running  WSearch            Windows Search

0 条评论

昵称

沙发空缺中,还不快抢~