2013-03-13 131 views
0

我有一個具有各種函數的模塊。我最近添加了一個函數。該函數接受一個參數,處理一些數據並調用其中的另一個函數。該函數接受一個字符串數組作爲參數。下面是代碼:在PowerShell 2.0中需要參數的函數內調用函數

 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

PowerShell讀取文件並同步執行內容。當你調用這個函數時,PowerShell並不知道它存在的原因,因爲它沒有解釋它。移到調用函數聲明後的函數。

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


    Function Analyze-ClientInstall 
    { 
     #[CmdletBinding()] 

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


    Analyze-ClientInstall $clientcheck 
} 
+0

謝謝,它工作。 – Rajiv 2013-03-13 13:47:32