Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a function in PowerShell

Tags:

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.

like image 753
user385028 Avatar asked Jul 06 '10 23:07

user385028


1 Answers

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.

like image 118
JaredPar Avatar answered Sep 22 '22 12:09

JaredPar