add tag
PeterVandivier
# How do I pin a range of allowable versions with both a minimum and maximum?

I am working on a module that depends on [Pester major version 4](https://pester-docs.netlify.app/docs/v4/introduction/installation). I would like to enforce in the module manifest that any major version 4 is acceptable, but nothing in v3 and nothing in v5.

If I declare in my manifest...

```powershell
    RequiredModules = @('Pester')
```

...then versions 3 or 5 will acceptably load on import and errors happen.

If I use...

```powershell
    RequiredModules = @(
        {
            ModuleName = 'Pester'
            ModuleVersion = '4.0'
        }
    )
```

...then version 3 is out but version 5 is in. Once again: errors happen.

I can evict version 5 with the property `MaximumVersion`...

```powershell
    RequiredModules = @(
        {
            ModuleName = 'Pester'
            MaximumVersion = '4.999'
        }
    )
```

...but then 3 is back in and to boot I think it's a bit gross to read `4.999` there.

Frustratingly, `MinimumVersion` is not an allowable property. Attempting to add it throws this error on import.

> Cannot convert value "System.Collections.Hashtable" to type "[Microsoft.PowerShell.Commands.ModuleSpecification](https://docs.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.modulespecification)". 
> Error: "The hashtable describing a module contains one or more members that are not valid. 
> The valid members are (ModuleName, ModuleVersion, RequiredVersion, GUID). **Remove the members that are not valid ('MinimumVersion'), then try again.**"

I've also tried using non-standard version numbers like "`4.*`" and "`4.x`" but the ModuleSpecification appears to require `major.minor` or else you get

> InvalidArgument: Cannot convert value "4.x" to type "System.Version". Error: "Input string was not in a correct format.

n.b. You can test allowable version strings using [`[version]'4.x'`](https://docs.microsoft.com/en-us/dotnet/api/system.version)

::: tio K8gvTy0qzkjNydFNzi9K/f8/ugzIz8zPi1U30atQ//8fAA
[version]'4.x'
```
Cannot convert value "4.x" to type "System.Version". 
Error: "Input string was not in a correct format."
+ [version]'4.x'
```
:::

So... how do I pin a range of allowable versions with both a minimum and maximum?
Top Answer
PeterVandivier
While it's frustrating that there's no alias, the `ModuleVersion` property enforces the `MinimumVersion`. 

Thus, on a machine with 3 available major versions of Pester (3,4,5), to import the middle version (4), you would use a manifest like the below

```powershell
    RequiredModules   = @(
        @{
            ModuleName = 'Pester'
            ModuleVersion = '4.0'
            MaximumVersion = '4.999'
            Guid = 'a699dea5-2c73-4616-a270-1f7abb777e71'
        }
    )
```

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.