PowerShell 2.0 and “The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program”

后端 未结 4 1325
北荒
北荒 2020-12-29 00:59

I am running Windows 7 RTM. PowerShell 2.0 is installed by default. I am using the excellent Windows PowerShell ISE to edit my scripts. I have the following script:

相关标签:
4条回答
  • 2020-12-29 01:36

    If your param($p) is not the first line in your script that can cause the Param error.

    Make sure your param($p) is the first line.

    0 讨论(0)
  • 2020-12-29 01:45

    Running this script,

    cls
    
    param([string]$Url, [string]$Template="CMSPUBLISHING#0")
    
    Write-Host "Url: $Url"  
    

    I got the same error

    The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    When I commented out the cls at the top it worked,

    #cls 
    
    param([string]$Url, [string]$Template="CMSPUBLISHING#0")
    
    Write-Host "Url: $Url"
    
    0 讨论(0)
  • 2020-12-29 01:54

    Also had this "kind" of problem, but I couldn`t run any of my ps1 scripts. Solution: Change encoding from UTF-8 (or which you have) to ANSI. Perhaps it will help someone too.

    0 讨论(0)
  • 2020-12-29 01:57

    I've solved the problem. I've corrected the description of the problem to make it accurate.

    The source of the problem is that I was incorrectly using the Param keyword multiple times. The correct usage is to declare multiple parameters within a single Param declaration like the following:

    Param($p, $d)
    

    This usage is explained in the Windows PowerShell Help article "about_Functions".

    0 讨论(0)
提交回复
热议问题