Error in PS Script while adding parameters

Welcome Forums General PowerShell Q&A Error in PS Script while adding parameters

This topic contains 1 reply, has 2 voices, and was last updated by

9 months ago.

  • Author
  • #124598

    Topics: 1
    Replies: 0
    Points: 11
    Rank: Member


    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 (


    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: (:) [New-CMAntimalwarePolicy], ParameterBindingException
    + FullyQualifiedErrorId : MissingArgument,Microsoft.ConfigurationManagement.Cmdlets.EP.Commands.NewAntimalwarePoli

  • #124616

    Topics: 0
    Replies: 29
    Points: 283
    Team MemberHelping Hand
    Rank: Contributor

    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!

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

The topic ‘Error in PS Script while adding parameters’ is closed to new replies.