2017-01-05 10 views
-1

PowerShellスクリプト内で関数を呼び出せない理由を教えてもらえますか?私のコードの下を参照してください:PowerShell ISE内で関数を呼び出す

Write-Host "Before calling Function." 

testFunction 

function testFunction() 
{ 
    Write-Host "Function has been called" 
} 

私は上記のコードを実行すると、私は次のようなエラーメッセージが出ます:私は同じPowerShellスクリプト内の関数を呼び出すことが可能でなければならないことを確信している

testFunction : The term 'testFunction' 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\andrew.short\Documents\Powershell\Backups\functionTest.ps1:3 char:1 
+ testFunction 
+ ~~~~~~~~~~~~ 
    + CategoryInfo   : ObjectNotFound: (testFunction:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException

を。誰か助けてもらえますか?

+1

実際、問題の原因がわかったかもしれません。関数を呼び出す前に関数が存在しなければならないと思います。 – ED209

+0

はい....これはうまくいくはずです: 'Write-Host '関数を呼び出す前に。 機能testFunction 正確Ed209 @ testFunction' – Hackerman

+0

{ 書き込みホスト "関数が呼び出されました"}。 –

答えて

2

の前に、それを使用してを宣言する必要があります。

Write-Host "Before calling Function." 

function testFunction { 
    Write-Host "Function has been called" 
} 

testFunction 
関連する問題