在需要PowerShell 2.0中的参数的函数内调用函数

时间:2013-03-13 13:14:33

标签: powershell

我有一个具有各种功能的模块。我最近添加了一个功能。该函数接受一个参数,处理一些数据并调用其中的另一个函数。此函数接受字符串数组作为参数。以下是代码:

        Function Get-CMClientInstall{
        some code..........

        Analyze-ClientInstall $clientcheck


        Function Analyze-ClientInstall
        {
            #[CmdletBinding()]

            PARAM (
            [Parameter(Mandatory=$true)][string[]]$CCMClients)
        }
     }

以下是错误消息:

The term 'Analyze-ClientInstall' 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.
At C:\Windows\system32\WindowsPowerShell\v1.0\Modules\ConfigMgrCommands\ConfigMgrCommands.psm1:475 char:34
+             Analyze-ClientInstall <<<<  $clientcheck
    + CategoryInfo          : ObjectNotFound: (Analyze-ClientInstall:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

有人可以建议吗?提前致谢。

1 个答案:

答案 0 :(得分:1)

PowerShell读取文件并同步执行内容。当你调用函数时,PowerShell没有它存在的线索,因为它还没有解释它。移动到函数声明后调用函数。

    Function Get-CMClientInstall{
    some code..........


    Function Analyze-ClientInstall
    {
        #[CmdletBinding()]

        PARAM (
        [Parameter(Mandatory=$true)][string[]]$CCMClients)
    }


    Analyze-ClientInstall $clientcheck
 }