PowerShell Get-Service 查看运行状态的服务并将信息保存成txt文件

Posted 师万物的博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PowerShell Get-Service 查看运行状态的服务并将信息保存成txt文件相关的知识,希望对你有一定的参考价值。

环境配置说明

  • Windows 21H1
  • PSVersion 5.1.19041.1320

示例

PS C:\\Users\\admin> Get-Service | Where-Object {$_.Status -eq "Running"}

Status   Name               DisplayName                           
------   ----               -----------                           
Running  Appinfo            Application Information               
Running  AppXSvc            AppX Deployment Service (AppXSVC)     
Running  AudioEndpointBu... Windows Audio Endpoint Builder        
Running  Audiosrv           Windows Audio                         
Running  BFE                Base Filtering Engine                 
Running  BrokerInfrastru... Background Tasks Infrastructure Ser...
Running  BthAvctpSvc        AVCTP 服务                              
Running  cbdhsvc_2b363      cbdhsvc_2b363                         
Running  CDPSvc             连接设备平台服务                              
Running  CDPUserSvc_2b363   CDPUserSvc_2b363                      
Running  ClipSVC            Client License Service (ClipSVC)      
Running  COMSysApp          COM+ System Application               
Running  CoreMessagingRe... CoreMessaging                         
Running  CryptSvc           Cryptographic Services                
Running  DcomLaunch         DCOM Server Process Launcher          
Running  DeviceAssociati... Device Association Service            
Running  Dhcp               DHCP Client                           
Running  DiagTrack          Connected User Experiences and Tele...
Running  DispBrokerDeskt... 显示策略服务                                
Running  DisplayEnhancem... 显示增强服务                                
Running  Dnscache           DNS Client                            
Running  DoSvc              Delivery Optimization                 
Running  DPS                Diagnostic Policy Service             
Running  DsmSvc             Device Setup Manager                  
Running  DusmSvc            数据使用量                                 
Running  EventLog           Windows Event Log                     
Running  EventSystem        COM+ Event System                     
Running  fdPHost            Function Discovery Provider Host      
Running  FDResPub           Function Discovery Resource Publica...
Running  FontCache          Windows Font Cache Service            
Running  gpsvc              Group Policy Client                   
Running  InstallService     Microsoft Store 安装服务                  
Running  iphlpsvc           IP Helper                             
Running  KeyIso             CNG Key Isolation                     
Running  LanmanServer       Server                                
Running  LanmanWorkstation  Workstation                           
Running  lfsvc              Geolocation Service                   
Running  LicenseManager     Windows 许可证管理器服务                      
Running  lmhosts            TCP/IP NetBIOS Helper                 
Running  LSM                Local Session Manager                 
Running  mpssvc             Windows Defender Firewall             
Running  MSDTC              Distributed Transaction Coordinator   
Running  NcbService         Network Connection Broker             
Running  NcdAutoSetup       Network Connected Devices Auto-Setup  
Running  netprofm           Network List Service                  
Running  NlaSvc             Network Location Awareness            
Running  nsi                Network Store Interface Service       
Running  OneSyncSvc_2b363   OneSyncSvc_2b363                      
Running  PcaSvc             Program Compatibility Assistant Ser...
Running  PlugPlay           Plug and Play                         
Running  Power              Power                                 
Running  ProfSvc            User Profile Service                  
Running  RmSvc              无线电管理服务                               
Running  RpcEptMapper       RPC Endpoint Mapper                   
Running  RpcSs              Remote Procedure Call (RPC)           
Running  SamSs              Security Accounts Manager             
Running  Schedule           Task Scheduler                        
Running  SecurityHealthS... Windows 安全中心服务                        
Running  SEMgrSvc           付款和 NFC/SE 管理器                        
Running  SENS               System Event Notification Service     
Running  SgrmBroker         System Guard 运行时监视器代理                 
Running  ShellHWDetection   Shell Hardware Detection              
Running  Spooler            Print Spooler                         
Running  SSDPSRV            SSDP Discovery                        
Running  StateRepository    State Repository Service              
Running  StorSvc            Storage Service                       
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  UserManager        User Manager                          
Running  UsoSvc             更新 Orchestrator 服务                    
Running  VaultSvc           Credential Manager                    
Running  VGAuthService      VMware Alias Manager and Ticket Ser...
Running  vm3dservice        VMware SVGA Helper Service            
Running  VMTools            VMware Tools                          
Running  Wcmsvc             Windows Connection Manager            
Running  wcncsvc            Windows Connect Now - Config Registrar
Running  WdiServiceHost     Diagnostic Service Host               
Running  WdiSystemHost      Diagnostic System 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  WpnService         Windows 推送通知系统服务                      
Running  WpnUserService_... WpnUserService_2b363                  
Running  wscsvc             Security Center                       
Running  WSearch            Windows Search                        
Running  wuauserv           Windows Update                        

信息保存至txt文件

PS C:\\Users\\admin> Get-Service | Where-Object {$_.Status -eq "Running"} | Out-File service_running.txt

txt文件内容


Status   Name               DisplayName                           
------   ----               -----------                           
Running  Appinfo            Application Information               
Running  AppXSvc            AppX Deployment Service (AppXSVC)     
Running  AudioEndpointBu... Windows Audio Endpoint Builder        
Running  Audiosrv           Windows Audio                         
Running  BFE                Base Filtering Engine                 
Running  BITS               Background Intelligent Transfer Ser...
Running  BrokerInfrastru... Background Tasks Infrastructure Ser...
Running  BthAvctpSvc        AVCTP 服务                              
Running  cbdhsvc_2b363      cbdhsvc_2b363                         
Running  CDPSvc             连接设备平台服务                              
Running  CDPUserSvc_2b363   CDPUserSvc_2b363                      
Running  ClipSVC            Client License Service (ClipSVC)      
Running  COMSysApp          COM+ System Application               
Running  CoreMessagingRe... CoreMessaging                         
Running  CryptSvc           Cryptographic Services                
Running  DcomLaunch         DCOM Server Process Launcher          
Running  DeviceAssociati... Device Association Service            
Running  Dhcp               DHCP Client                           
Running  DiagTrack          Connected User Experiences and Tele...
Running  DispBrokerDeskt... 显示策略服务                                
Running  DisplayEnhancem... 显示增强服务                                
Running  Dnscache           DNS Client                            
Running  DoSvc              Delivery Optimization                 
Running  DPS                Diagnostic Policy Service             
Running  DsmSvc             Device Setup Manager                  
Running  DusmSvc            数据使用量                                 
Running  EventLog           Windows Event Log                     
Running  EventSystem        COM+ Event System                     
Running  FDResPub           Function Discovery Resource Publica...
Running  FontCache          Windows Font Cache Service            
Running  gpsvc              Group Policy Client                   
Running  InstallService     Microsoft Store 安装服务                  
Running  iphlpsvc           IP Helper                             
Running  KeyIso             CNG Key Isolation                     
Running  LanmanServer       Server                                
Running  LanmanWorkstation  Workstation                           
Running  lfsvc              Geolocation Service                   
Running  LicenseManager     Windows 许可证管理器服务                      
Running  lmhosts            TCP/IP NetBIOS Helper                 
Running  LSM                Local Session Manager                 
Running  mpssvc             Windows Defender Firewall             
Running  MSDTC              Distributed Transaction Coordinator   
Running  NcbService         Network Connection Broker             
Running  NcdAutoSetup       Network Connected Devices Auto-Setup  
Running  netprofm           Network List Service                  
Running  NlaSvc             Network Location Awareness            
Running  nsi                Network Store Interface Service       
Running  OneSyncSvc_2b363   OneSyncSvc_2b363                      
Running  PcaSvc             Program Compatibility Assistant Ser...
Running  PlugPlay           Plug and Play                         
Running  Power              Power                                 
Running  ProfSvc            User Profile Service                  
Running  RmSvc              无线电管理服务                               
Running  RpcEptMapper       RPC Endpoint Mapper                   
Running  RpcSs              Remote Procedure Call (RPC)           
Running  SamSs              Security Accounts Manager             
Running  Schedule           Task Scheduler                        
Running  SecurityHealthS... Windows 安全中心服务                        
Running  SEMgrSvc           付款和 NFC/SE 管理器                        
Running  SENS               System Event Notification Service     
Running  SgrmBroker         System Guard 运行时监视器代理                 
Running  ShellHWDetection   Shell Hardware Detection              
Running  Spooler            Print Spooler                         
Running  SSDPSRV            SSDP Discovery                        
Running  StateRepository    State Repository Service              
Running  StorSvc            Storage Service                       
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  TrustedInstaller   Windows Modules Installer             
Running  UserManager        User Manager                          
Running  UsoSvc             更新 Orchestrator 服务                    
Running  VaultSvc           Credential Manager                    
Running  VGAuthService      VMware Alias Manager and Ticket Ser...
Running  vm3dservice        VMware SVGA Helper Service            
Running  VMTools            VMware Tools                          
Running  Wcmsvc             Windows Connection Manager            
Running  wcncsvc            Windows Connect Now - Config Registrar
Running  WdiServiceHost     Diagnostic Service Host               
Running  WdiSystemHost      Diagnostic System 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  wlidsvc            Microsoft Account Sign-in Assistant   
Running  WpnService         Windows 推送通知系统服务                      
Running  WpnUserService_... WpnUserService_2b363                  
Running  wscsvc             Security Center                       
Running  WSearch            Windows Search                        
Running  wuauserv           Windows Update                        

学习资料


感恩曾经帮助过 师万物 的人。
学有余力的话,可以了解具有开源、跨平台特性的Powershell Core。
欢迎关注公众号:悟为生心

以上是关于PowerShell Get-Service 查看运行状态的服务并将信息保存成txt文件的主要内容,如果未能解决你的问题,请参考以下文章

如何使用Get-Service命令提取Windows服务的物理路径

使用PowerShell操作Windows服务的命令小结

PowerShell Format-Wide 设置显示的列数

PowerShell-自定义函数-位置参数:Position

获取已禁用/已停止服务的关联应用程序

powershell 在PowerShell中快速查看模块源代码