> 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-pmpcscriptrule.md). Agents can also search and read this documentation through its [MCP server](https://docs.patchmypc.com/~gitbook/mcp).

# New-PmpcScriptRule

Builds a script rule.

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

## Synopsis

Builds a script rule.

## Syntax

{% code collapsedlinecount="10" %}

```powershell
New-PmpcScriptRule [-DisplayName] <String> [-ScriptContent] <String>
  [-OperationType] <ScriptRuleOperationType> [-Operator <RuleOperator>]
  [-ComparisonValue <String>] [-RunAsUser] [-EnforceSignatureCheck] [-RunAs32Bit]
  [<CommonParameters>]
```

{% endcode %}

## Description

Creates a script rule for use in a detection rule set or a requirement set.

Supply the script contents rather than a path: the rule travels to Intune, which has no access to a file on the machine that built it.

## Parameters

### -ComparisonValue

Value the script's output is compared against.

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

### -DisplayName

Name shown for the rule.

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

### -EnforceSignatureCheck

Require the script to be signed by a trusted publisher.

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

### -OperationType

Type the script's output is interpreted as.

| Attribute       | Value                                                             |
| --------------- | ----------------------------------------------------------------- |
| Type            | `ScriptRuleOperationType`                                         |
| Required        | True                                                              |
| Position        | 2                                                                 |
| Pipeline input  | True (ByPropertyName)                                             |
| Aliases         | None                                                              |
| Accepted values | NotConfigured, String, DateTime, Integer, Float, Version, Boolean |

### -Operator

How the script's output is compared with -ComparisonValue.

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

### -RunAs32Bit

Run the script in a 32-bit host on a 64-bit system.

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

### -RunAsUser

Run the script as the signed-in user instead of the system account.

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

### -ScriptContent

The script itself, as text rather than a path.

| Attribute      | Value                 |
| -------------- | --------------------- |
| Type           | `System.String`       |
| Required       | True                  |
| Position       | 1                     |
| 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

### ScriptRuleDto

The script rule.

## Examples

### Example 1: Detect with a script

{% code collapsedlinecount="10" %}

```powershell
$script = Get-Content .\detect.ps1 -Raw
New-PmpcScriptRule -DisplayName 'Contoso detection' -ScriptContent $script -OperationType Boolean -Operator Equal -ComparisonValue 'true'
```

{% endcode %}

Reads the script from disk and sends its contents, not its path.

## Notes

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

## Related links

* [New-PmpcDetectionRule](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcdetectionrule.md)
* [New-PmpcRequirement](https://docs.patchmypc.com/patch-my-pc-cloud-api/powershell/new-pmpcrequirement.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-pmpcscriptrule.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.
