1
私はPowershellを学習する過程にあり、別の関数を呼び出すことができない状況に遭遇しましたか?Powershellが別の関数を呼び出す
私のテストスクリプトは、次のコードを持っている:
Import-Module PSStdLib -Verbose -Force
plSetLevel 12
インポートモジュールは、次のコードがあります
function plFileAppend {
<#
.SYNOPSIS
.DESCRIPTION
.PARAMETER FileName
FileName
.PARAMETER Output
Output
.PARAMETER Variables
Variables
.EXAMPLE
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, ParameterSetName="Default", Position=1)]
[Parameter(Mandatory=$true, ParameterSetName="Variable", Position=1)]
[ValidateNotNullOrEmpty()]
[String]$FileName,
[Parameter(Mandatory=$true, ParameterSetName="Default", Position=2)]
[Parameter(Mandatory=$true, ParameterSetName="Variable", Position=2)]
[String]$Output,
[Parameter(Mandatory=$true, ParameterSetName="Variable", Position=3)]
[String[]]$Variables
)
# Scan the output for variable markers.
$lVarsInOutput = ($Output.ToCharArray() | Where-Object {$_ -eq '{'} | Measure-Object).Count
# No variable substitutions.
if ($lVarsInOutput -eq 0) {
$Output | Out-File $FileName -Append
} else {
# Variables passsed to substitute into output.
$lVaiablesOut = $Variables[ 0..($lVarsInOutput-1) ]
$Output -f $lVaiablesOut | Out-File $FileName -Append
}
}
上記関数の定義の後に....
function plSetLevel {
<#
.SYNOPSIS
.DESCRIPTION
.PARAMETER Output
Step
.EXAMPLE
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNullOrEmpty()]
[ValidateRange(1,9999)]
[int]$Step
)
if (plIfExists($psRestartFile)) { Remove-Item $psRestartFile }
plFileAppend $psRestartFile "STAMP=$psExecStamp"
plFileAppand $psRestartFile "PID=$psPID"
plFileAppand $psRestartFile "STEP=$Step"
}
plSetLevel関数を実行しようとすると、次のような結果になります。
plFileAppand : The term 'plFileAppand' 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 S:\PS\Home\Library\PSStdLib\PSStdLib.psm1:1093 char:5
+ plFileAppand $psRestartFile "PID=$psPID"
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (plFileAppand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
plFileAppand : The term 'plFileAppand' 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 S:\PS\Home\Library\PSStdLib\PSStdLib.psm1:1094 char:5
+ plFileAppand $psRestartFile "STEP=$Step"
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (plFileAppand:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
モジュールをVerbose and Forceでインポートしました。出力が正しい順序でロードされているようですか?私はGoogleが発見した
VERBOSE: Loading module from path 'S:\PS\Home\Library\PSStdLib\PSStdLib.psm1'.
VERBOSE: Importing function 'plDebugPrint'.
VERBOSE: Importing function 'plFileAppend'.
VERBOSE: Importing function 'plGetKeyValue'.
VERBOSE: Importing function 'plGetKeyValues'.
VERBOSE: Importing function 'plIfExists'.
VERBOSE: Importing function 'plOSInfo'.
VERBOSE: Importing function 'plSetLevel'.
すべてが呼び出される関数の定義は、呼び出し元の関数の前になければならない状況に対処するようです。それはここではそうではないようです。私は何が欠けていますか? Powershellはある関数を別の関数から呼び出すことはできませんか? 範囲の問題と思われますか?私はこの問題を解決することができる方法はありますか、それでもコードは機能していますか?
に変更されました。私はそれが何かシンプルだと分かっていましたが、シシュ。今日はコーヒーが足りません –
私たちにとっても最高の出来栄えです;-) –