# Module advanced parameters

**URL:** <https://forums.powershell.org/t/module-advanced-parameters/15458>\
**Category:** PowerShell Help\
**Created:** [January 5, 2021, 8:09am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458 "2021-01-05T08:09:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![metablaster](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/metablaster/32/1224_2.png) [@metablaster](https://forums.powershell.org/u/metablaster)\
**Post date:** [January 5, 2021, 8:09am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/1 "2021-01-05T08:09:38Z")

</div>

Maybe I should have titled this as “Advanced modules” (joke lol)…

I need to pass parameters to modules so first line of my module looks like this:

`param (`

` [TypeName] $ParameterName`

`)`

This works just fine, but I'm wondering if modules (\*.psm1) files can accept parameters, then what would be the purpose of defining a full param block just like for advanced functions?

`[CmdletBinding()]`

`param (`

` [Parameter()]`

` [TypeName] $ParameterName`

`)`

Surely it looks very strange but not enough because I didn't define some parameter set names, some arguments such as Mandatory or HelpURI, and OutputType attribute etc. etc.

Advanced parameters are designed for functions and scripts but not for \*.PSM modules AFAIK.

My question is, is there any benefit of module advanced parameters and to which extent? ex.

What would be considered too much and is there any known benefit when using full param block does make benefit?

Or maybe asking another way around makes more sense: Which portion of advanced parameter block features would make absolutely no sense or benefit for modules?

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 5, 2021, 8:29am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/2 "2021-01-05T08:29:34Z")

</div>

You can have parameters in a script module. This is commonly used to add the “Prefix” parameter to give distinctive noun names to imported commands or the “NoClobber” parameter to prevent overriding existing commands in the session. The Import-Module cmdlet has an -ArgumentList parameter that can be used to pass parameter values to the script module.

&nbsp;

See: Get-Help [Import-Module](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-5.1), Get-Help [about\_modules](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-5.1)

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![metablaster](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/metablaster/32/1224_2.png) [@metablaster](https://forums.powershell.org/u/metablaster)\
**Post date:** [January 5, 2021, 8:39am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/3 "2021-01-05T08:39:43Z")

</div>

NoClobber and Prefix make sense.

In other words Parameter and cmdletbinding attributes make no sense? (even though we can define them and it will work)

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 5, 2021, 8:44am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/4 "2021-01-05T08:44:39Z")

</div>

There might be a use case, but I can’t think of one.

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [January 5, 2021, 9:23am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/5 "2021-01-05T09:23:59Z")

</div>

@Mike R: This is a bit of a segway on the original post. I have a large script that accepts 7 parameters. In the main script, I load a module with all my functions. What I have been doing when calling those module functions that require the values from the main script parameters is to pass them as parameters to the functions. Would I be better off passing them as Module parameters? What would be the best practice?

Thanks for any guidance you can provide.

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 5, 2021, 10:30am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/6 "2021-01-05T10:30:18Z")

</div>

I would keep them in the functions. This would give you the most flexibility. Are you using splatting to pass the parameter values to your functions? If not, this could significantly reduce the syntax complexity by only modifying the hashtable for specific changes in parameter names/values. For example, consider the following script:

```
[cmdletbinding()]
param (
    $param1, $param2, $param3, $param4
)

function MyFunction ($param1, $param2, $param3, $param4)
{
    "You passed in $param1, $param2, $param3, $param4"
}

MyFunction @PSBoundParameters
```

Notice I used splatting on the function call and passed the hashtable PSBoundParameters which is an automatic hashtable created for bound parameters. This works because the parameters required for the function are the same as the script. If the were different I could create a different hashtable or copy the PSBoundParameters hashtable to modify it as needed.

Here’s what that script does when I call it.

```
PS C:\Users\micha> .\args.ps1 -param1 "Hello" -param2 "World" -param3 "foo" -param4 "Bar"
You passed in Hello, World, foo, Bar
```

&nbsp;

Recommend review Get-Help [about\_splatting](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-5.1), Get-Help [about\_automatic\_variables](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-5.1)

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [January 5, 2021, 11:22am UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/7 "2021-01-05T11:22:34Z")

</div>

Perfect, thank you sir 🙂

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/module-advanced-parameters/15458/8 "2024-05-16T20:28:02Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


