> For the complete documentation index, see [llms.txt](https://poshcode.gitbook.io/powershell-practice-and-style/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://poshcode.gitbook.io/powershell-practice-and-style/best-practices/language-interop-and-.net.md).

# Language, Interop and .NET

## VER-01 Write for the lowest version of PowerShell that you can

As a rule, write for the lowest PowerShell version that you can, especially with scripts that you plan to share with others. Doing so provides the broadest compatibility for other folks.

That said, don't sacrifice functionality or performance just to stick with an older version. If you can safely write for a higher version (meaning you've deployed it everywhere the script will need to run), then take advantage of that version. Keep in mind that some newer features that seem like window dressing might actually have underlying performance benefits. For example, in PowerShell v3:

```
Get-Service | Where-Object -FilterScript { $\_.Status -eq 'Running' }
```

Will run significantly slower than:

```
Get-Service | Where Status -eq Running
```

because of the way the two different syntaxes have to be processed under the hood.

*Further information:* You can get some detail on the differences between versions of Powershell by typing `help about\Windows\PowerShell\2.0` (or 3.0 or 4.0) in Powershell

## VER-02 Document the version of PowerShell the script was written for

All that said, make sure you specify the version of PowerShell you wrote for by using an appropriate `#requires` statement:

```
#requires -version 3.0
```

The `#requires` statement will prevent the script from running on the wrong version of PowerShell.

#### PowerShell Supported Version

When working in an environment where there are multiple versions of PowerShell make sure to specify the lowest version your script will support by providing a Requires statement at the top of the script.

```
    #Requires -Version 2.0
```

When a *module* uses specific cmdlets or syntax that is only present on a specific minimum version of PowerShell in the module manifest ps1d file.

```
    PowerShellVersion = '3.0'
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://poshcode.gitbook.io/powershell-practice-and-style/best-practices/language-interop-and-.net.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
