在PowerShell 2.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
可有人请指教?提前致谢。
答
PowerShell读取文件并同步执行内容。当你调用这个函数时,PowerShell并不知道它存在的原因,因为它没有解释它。移到调用函数声明后的函数。
Function Get-CMClientInstall{
some code..........
Function Analyze-ClientInstall
{
#[CmdletBinding()]
PARAM (
[Parameter(Mandatory=$true)][string[]]$CCMClients)
}
Analyze-ClientInstall $clientcheck
}
谢谢,它工作。 – Rajiv 2013-03-13 13:47:32