> For the complete documentation index, see [llms.txt](https://docs.patchmypc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcdetectionrule.md). Agents can also search and read this documentation through its [MCP server](https://docs.patchmypc.com/~gitbook/mcp).

# New-PmpcDetectionRule

Builds a detection rule set.

[Back to the Cloud Customer API overview](https://docs.patchmypc.com/patch-my-pc-cloud-api)

## Synopsis

Builds a detection rule set.

## Syntax

{% code collapsedlinecount="10" %}

```powershell
New-PmpcDetectionRule [-RulesType] <DetectionRuleType> [-FileRule <FileRuleDto[]>]
  [-RegistryRule <RegistryRuleDto[]>] [-ScriptRule <ScriptRuleDto>]
  [-ProductCode <String>] [-ProductVersion <String>] [-ProductCodeOperator <RuleOperator>]
  [<CommonParameters>]
```

{% endcode %}

## Description

Creates the detection rule set that says whether an application is already installed, as accepted by New-PmpcCustomApplication and Update-PmpcCustomApplication.

Rules come from New-PmpcFileRule, New-PmpcRegistryRule and New-PmpcScriptRule. A product-code rule is built here rather than by a separate cmdlet because an application has only one MSI product code, so there is nothing to compose.

## Parameters

### -FileRule

File and folder rules.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `FileRuleDto[]`       |
| Required       | False                 |
| Position       | Named                 |
| Pipeline input | True (ByPropertyName) |
| Aliases        | FileSystemRules       |

### -ProductCode

MSI product code identifying the installed application.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `System.String`       |
| Required       | False                 |
| Position       | Named                 |
| Pipeline input | True (ByPropertyName) |
| Aliases        | None                  |

### -ProductCodeOperator

How the installed product version is compared with -ProductVersion.

| Attribute       | Value                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------ |
| Type            | `RuleOperator`                                                                             |
| Required        | False                                                                                      |
| Position        | Named                                                                                      |
| Pipeline input  | True (ByPropertyName)                                                                      |
| Aliases         | None                                                                                       |
| Accepted values | NotConfigured, Equal, NotEqual, GreaterThan, GreaterThanOrEqual, LessThan, LessThanOrEqual |

### -ProductVersion

Product version compared against the installed one. Requires -ProductCode.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `System.String`       |
| Required       | False                 |
| Position       | Named                 |
| Pipeline input | True (ByPropertyName) |
| Aliases        | None                  |

### -RegistryRule

Registry rules.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `RegistryRuleDto[]`   |
| Required       | False                 |
| Position       | Named                 |
| Pipeline input | True (ByPropertyName) |
| Aliases        | RegistryRules         |

### -RulesType

Which detection strategy the application uses.

| Attribute       | Value                      |
| --------------- | -------------------------- |
| Type            | `DetectionRuleType`        |
| Required        | True                       |
| Position        | 0                          |
| Pipeline input  | True (ByPropertyName)      |
| Aliases         | None                       |
| Accepted values | None, PMPC, Script, Manual |

### -ScriptRule

Script rule. Only one is carried, so this is not a collection.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `ScriptRuleDto`       |
| Required       | False                 |
| Position       | Named                 |
| Pipeline input | True (ByPropertyName) |
| Aliases        | None                  |

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about\_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## Inputs

### None

This cmdlet does not accept pipeline input by value.

## Outputs

### DetectionRulesDto

The detection rule set.

## Examples

### Example 1: Detect by MSI product code

{% code collapsedlinecount="10" %}

```powershell
New-PmpcDetectionRule -RulesType PMPC -ProductCode '{12345678-1234-1234-1234-123456789012}'
```

{% endcode %}

Detects the application by the product code its MSI registers.

### Example 2: Detect by file and registry

{% code collapsedlinecount="10" %}

```powershell
$file = New-PmpcFileRule -Path 'C:\Program Files\Contoso' -FileOrFolderName 'app.exe' -OperationType Exists
$reg  = New-PmpcRegistryRule -KeyPath 'HKLM:\SOFTWARE\Contoso\App' -OperationType Exists
New-PmpcDetectionRule -RulesType Manual -FileRule $file -RegistryRule $reg
```

{% endcode %}

Combines rules built by the rule cmdlets into one set.

## Notes

This cmdlet makes no network call and does not require a session.

## Related links

* [New-PmpcFileRule](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcfilerule.md)
* [New-PmpcRegistryRule](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcregistryrule.md)
* [New-PmpcScriptRule](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcscriptrule.md)
* [New-PmpcCustomApplication](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpccustomapplication.md)
* [PowerShell module](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell.md)

## See also

This cmdlet has no SDK method or REST operation of its own.

* [Cross-reference: cmdlets, SDK methods, and REST operations](https://docs.patchmypc.com/patch-my-pc-cloud-api/cross-reference.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcdetectionrule.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
