Running a function in PowerShell
I am new to PS and have been given a script to run. The first thing I do is type in c:\powershell\ir.ps1
. This seems to work. Then after defining my开发者_如何转开发 clients directory I am supposed to be able to just type in functions such as ir-n
. This worked at the person's desk that showed me how to do it, but I get the following error:
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
Is there something simple I can do to get it to run? I see the function in the ir.ps1
file so I know it is there.
It looks like you are running the ir.ps1
script when you should be sourcing it. I'm guessing that the ir.ps1
file is defining a function named ir-n
. In that case running the script will not define the function in the script's context but not the command window. You need to source the script to get it to persist in the command window.
Try running the following
PS$> . c:\powershell\ir.ps1
After running this then try ir-n
.
You probably need to dot source
the script which will leave the functions it defines available in the global scope e.g.:
PS> . c:\powershell\ir.ps1
精彩评论