You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Get-Service/Get-Process参数使用疑问:如何同时启用两个参数?

How to Combine Parameters for Get-Service or Get-Process in PowerShell

Hey there! It’s super common to run into parameter conflicts or unexpected behavior when trying to mix parameters in PowerShell cmdlets like Get-Service or Get-Process—the key issue usually boils down to parameter sets (PowerShell groups parameters into sets that work together, and you can’t use parameters from conflicting sets at the same time). Let’s walk through how to fix this:

1. First, Check Which Parameters Can Work Together

Before you spend time troubleshooting, verify which parameters are compatible by checking the cmdlet’s syntax. Run this command in your PowerShell console:

# For Get-Service
Get-Command Get-Service -Syntax

# For Get-Process
Get-Command Get-Process -Syntax

You’ll see output grouped into parameter sets (marked with []). Parameters separated by | are mutually exclusive—you can’t use both in the same command. For example, in Get-Process, -Id and -Name are in separate parameter sets for direct filtering, so you can’t use them together directly.

2. Fixes for Common Scenarios

Scenario A: Parameters Are in the Same Set (But Not Working)

If you’re using parameters that should work together but they’re not, double-check:

  • Spelling and capitalization: PowerShell is case-insensitive, but typos (like -Stat instead of -Status) will break things.
  • Wildcard usage: If you’re filtering names, make sure you’re using * correctly (e.g., -Name *chrome* instead of -Name chrome if you want partial matches).
  • Value formatting: Some parameters require specific values (e.g., -Status Running—not -Status "running" is fine, but avoid typos like -Status Run).

Scenario B: Parameters Are Mutually Exclusive

If the parameters you want to use are in conflicting sets, use a pipeline with Where-Object to combine your filters instead. Here are examples:

Example 1: Filter Get-Process by Name and CPU Usage

Suppose you want processes named "chrome" with CPU usage over 5%—you can’t do this directly with Get-Process parameters, so pipe to Where-Object:

Get-Process -Name chrome* | Where-Object {$_.CPU -gt 5}

Example 2: Filter Get-Service by Name and Startup Type

If you want services starting with "Win" that have a startup type of "Automatic", use:

Get-Service -Name Win* | Where-Object {$_.StartType -eq "Automatic"}

3. Pro Tip: Use Get-Help for Details

For deeper info on each parameter and their compatibility, run:

Get-Help Get-Service -Detailed
# Or
Get-Help Get-Process -Detailed

This will break down each parameter set and explain exactly how they work together.

If you can share the exact parameters you’re trying to combine, I can give you a more specific solution! 😊

内容的提问来源于stack exchange,提问作者Daniel Ben Eliyahu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:15:58