Error in PS Script while adding parameters

Hello,

Getting started with PS scripting and putting together few scripts that helps in my day to day work. I am receiving the below error when I try and pass few parameters in the below script. The details are as below. What am I doing wrong ?

Script I am running is below.

Param (
[Parameter(Mandatory=$True)]
[string]$Name,

[Parameter(Mandatory=$True)]
[string]$Description)

New-CMAntimalwarePolicy -Name -Policy ExclusionSettings -Description -Verbose

It asks me to enter Name and Description just fine but when I hit enter again I get the below error.

New-CMAntimalwarePolicy : Missing an argument for parameter ‘Name’. Specify a parameter of type ‘System.String’ and
try again.
At line:9 char:25

  • New-CMAntimalwarePolicy -Name -Policy ExclusionSettings -Description …
  •                     ~~~~~
    
  • CategoryInfo : InvalidArgument: (:slight_smile: [New-CMAntimalwarePolicy], ParameterBindingException
  • FullyQualifiedErrorId : MissingArgument,Microsoft.ConfigurationManagement.Cmdlets.EP.Commands.NewAntimalwarePoli
    cyCommand

So, the first problem here is that you’re apparently setting parameters, but never using the variables that you create.

When you are calling a function or script with arguments, you need to specify the value that you pass - so, “-Name” should be “-Name $Name” (using the parameter you created). It doesn’t get automatically passed down!

[pre]param(
[Parameter(Mandatory=$true)]
[string]$Name,

[Parameter(Mandatory=$true)]
[string]$Description

)

New-CMAntimalwarePolicy -Name $Name -Policy ‘ExclusionSettings’ -Description $Description -Verbose[/pre]