2010-07-06 192 views
4

我是PS新手,已經給腳本運行了。我做的第一件事是輸入c:\powershell\ir.ps1。這似乎工作。然後,在定義我的客戶目錄後,我應該能夠輸入諸如ir-n之類的函數。這個工作在人的辦公桌上顯示,我該怎麼做,但我得到了以下錯誤:在PowerShell中運行一個函數

The term 'ir-n' 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 line:1 char:5 
+ ir-n <<<< 
    + CategoryInfo   : ObjectNotFound: (ir-n:String) [], CommandNotFoundException 
    + FullyQualifiedErrorId : CommandNotFoundException 

有什麼簡單的,我可以做的就是它運行?我看到ir.ps1文件中的功能,所以我知道它在那裏。

回答

6

看起來您正在運行ir.ps1腳本,當您應該採購它時。我猜測ir.ps1文件正在定義一個名爲ir-n的函數。在這種情況下,運行腳本不會在腳本的上下文中定義函數,而不會在命令窗口中定義函數。您需要獲取腳本以使其保留在命令窗口中。

嘗試運行以下

PS$> . c:\powershell\ir.ps1 

運行之後再嘗試ir-n

+0

你們和這個論壇是真棒......它的工作。如果我不能回來,我會看看我現在能否完成。謝謝! – user385028 2010-07-07 01:21:12

+0

如果這個工作,你應該接受這個答案。 – JMD 2015-02-24 17:41:33

+0

我不敢相信你注意到答案很好,還沒有接受。我相信這只是一個簡單的監督。 :) – 2017-11-06 12:50:56

2

你可能需要dot source該腳本會離開它定義可用的功能在全球範圍內例如爲:

PS> . c:\powershell\ir.ps1 
相關問題