Function PowerShell-无法识别该函数
我是新加入PowerShell的,我有一个无法解决的问题。 我必须让我的函数连续分析很多文件夹,但当我给函数指定参数时,我的程序无法工作Function PowerShell-无法识别该函数,function,powershell,Function,Powershell,我是新加入PowerShell的,我有一个无法解决的问题。 我必须让我的函数连续分析很多文件夹,但当我给函数指定参数时,我的程序无法工作 Param( [string]$fPath ) analyse $fPath $importList = get-content -Path C:\Users\lamaison-e\Documents\multimediaList.txt $multimediaList = $importList.Split(',') function an
Param(
[string]$fPath
)
analyse $fPath
$importList = get-content -Path C:\Users\lamaison-e\Documents\multimediaList.txt
$multimediaList = $importList.Split(',')
function analyse{
Param(
[parameter(Mandatory=$true)]
[String]
$newPath
)
cd $newPath
$Resultat = "Dans le dossier " + $(get-location) + ", il y a " + $(mmInCurrentDir) + " fichier(s) multimedia pour un total de " + $(multimediaSize) + " et il y a " + $(bInCurrentDir) + " documents de bureautique pour un total de " + $(bureautiqueSize) + ". La derniere modification du dossier concerne le fichier " + $(modifDate)
$Resultat
}
当“分析”不存在时,它就起作用了,但之后就停止了。CommandNoFoundException。这可能是一个愚蠢的错误,但我不能处理它。。。感谢您的时间。解析器将逐行读取类似您的PowerShell脚本 在解析
analyze$fpath
的时间点,函数analyze
不存在于当前作用域中,因为函数定义在脚本的更下方
要在脚本中使用内联函数,请在调用定义之前将其上移一点:
Param(
[string]$fPath
)
# Define the function
function analyse{
Param(
[parameter(Mandatory=$true)]
[String]
$newPath
)
cd $newPath
$Resultat = "Dans le dossier " + $(get-location) + ", il y a " + $(mmInCurrentDir) + " fichier(s) multimedia pour un total de " + $(multimediaSize) + " et il y a " + $(bInCurrentDir) + " documents de bureautique pour un total de " + $(bureautiqueSize) + ". La derniere modification du dossier concerne le fichier " + $(modifDate)
$Resultat
}
# Now you can use it
analyse $fPath
$importList = get-content -Path C:\Users\lamaison-e\Documents\multimediaList.txt
$multimediaList = $importList.Split(',')
函数
不是声明,而是创建/修改函数必须执行的命令。