Issue
i can not call a In-Script Function without PowerShell ISE
When i call a function in the normal Powershell i get this Error
onboarding : The term "onboarding" was not used as the name of a cmdlet, function, script file, or
of an executable program. Check the spelling of the name or if the path is correct (if
included) and repeat the process.
In *************************************.ps1:8 characters:9
+ onboarding
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (onboarding:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Solution
Have in mind Mathias R. Jessen’s useful comment (valid for ▶
button as well):
When you use F5 to run a script in ISE, it doesn’t actually
invoke the script, it executes the contents of the editor in the
global scope of the attached console/runspace, so it’ll persist after
the first attempt.
Run your script using Dot sourcing operator .
Runs a script in the current scope so that any functions, aliases, and
variables that the script creates are added to the current scope,
overriding existing ones. Parameters declared by the script become
variables. Parameters for which no value has been given become
variables with no value. However, the automatic variable$args
is
preserved.Example:
. c:\scripts\sample.ps1 1 2 -Also:3
Note. The dot sourcing operator is followed by a space. Use the space
to distinguish the dot from the dot (.
) symbol that represents the
current directory.
Answered By – JosefZ
Answer Checked By – Candace Johnson (BugsFixing Volunteer)