Running a function in PowerShell

I am new to PS and got a script run. The first thing I do is enter c:\powershell\ir.ps1 . It seems to work. Then, after defining the directory of my clients, I should be able to simply enter functions such as ir-n . This worked on a personal table that showed me how to do this, 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 run it? I see the function in the ir.ps1 file, so I know that it is.

+4
source share
2 answers

It looks like you are running the ir.ps1 script when you should look for it. I assume that the ir.ps1 file defines a function called ir-n . In this case, running the script will not define the function in the context of the script, and not in the command window. You need to specify the script so that it is saved in the command window.

Try the following

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

After starting, try ir-n .

+6
source

You probably need a dot source script that will leave the functions that it defines available in the global scope, for example:

 PS> . c:\powershell\ir.ps1 
+2
source

Source: https://habr.com/ru/post/1314894/


All Articles