locked
Error in PS Script RRS feed

  • Question

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


    Naga Sai Jonnavithula

    Wednesday, November 14, 2018 6:04 AM

Answers

  • Be fore trying to writ CmdLets you need to learn how to use CmdLets.  You must supply values for a CmdLet.

    Also do not make the new user mistake of trying to wrap every CmdLet in a function.  It serves no purpose.

    You must start by learning PowerShell. Without any basic programming training you will find learning and using PowerShell beyond just typing at the prompt a very painful learning experience.

    First go here: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell

    Also be sure to always read the help for each item you wish to use.

    help about_functions

    You also need to read the error message carefully as they tell you exactly what is wrong and much of the time tell you how to fix the issue.  That is the case here:

    New-CMAntimalwarePolicy : Missing an argument for parameter 'Name'

    It is telling you that you have not supplied a value for the parameter called "Name".  In your code you have not supplied values for any of the parameters you have used.


    \_(ツ)_/


    • Marked as answer by Naga Sai J Friday, November 16, 2018 7:17 AM
    • Edited by jrv Friday, November 16, 2018 9:04 AM
    Wednesday, November 14, 2018 6:20 AM