术语“ PowerShell无法识别”

时间:2020-05-14 07:33:19

标签: function powershell import module runtime-error

在我的脚本中,我声明了该函数,然后使用GetNewClosure对其进行了调用。该函数是我创建的大量按钮的事件处理程序。当我在ISE中运行它时,一切都很好,但是当我尝试运行脚本时,它向我显示错误:"filling : The term 'filling' 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:\Users\klima\Desktop\SYOP\KolkoiKrzyzyk.ps1:210 char:38 + $Button[$i,$j].Add_Click({filling -a $i -b $j}.GetNewC ... + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (filling:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException。拼写很好,我在调用它之前声明了该函数。我做了研究,我知道“ GetNewClosure”会创建新模块。谁能告诉我如何导入此模块?我在下面显示代码:

Function filling{
Param(
[int]
$a,
[int]
$b)

    if ($a -lt 9 -and $b -eq 0){ 
        if($Script:who -eq $true){
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\kolko.jpg")
            $Script:P[$a]= "o" 
            Set-Variable who -Value $false -Scope Script
            }

        else{
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\krzyzyk.jpg")
            $Script:P[$a]= "x" 
            Set-Variable who -Value $true -Scope Script
            }
    }
    if ($a -lt 9 -and $b -eq 1){
        if($Script:who -eq $true){
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\kolko.jpg")
            $Script:P[($b*10 + $a) - 1]= "o" 
            Set-Variable who -Value $false -Scope Script
            }

        else{
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\krzyzyk.jpg")
            $Script:P[($b*10 + $a) - 1]= "x" 
            Set-Variable who -Value $true -Scope Script
            }
    }
    if ($a -lt 9 -and $b -eq 2){
        if($Script:who -eq $true){
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\kolko.jpg")
            $Script:P[($b*10 + $a) - 2]= "o" 
            Set-Variable who -Value $false -Scope Script
            }

        else{
            $Button[$a,$b].Image=[System.Drawing.Image]::FromFile("$env:UserProfile\Deswhop\SYOP\krzyzyk.jpg")
            $Script:P[($b*10 + $a) - 2]= "x" 
            Set-Variable who -Value $true -Scope Script
            }
    }

$Button[$a,$b].Enabled=$false
}

for([int]$i=0;$i -lt 9 ; $i++){
        for([int]$j=0;$j -lt 3 ; $j++){
            $Button[$i,$j].Add_Click({filling -a $i -b $j}.GetNewClosure()) 

    }
}

0 个答案:

没有答案