ajax
ajax

Reputation: 317

Unable to load .ps1 powershell script from Powershell command (console)

I am stuck in this weird problem where I am trying to execute a powershell script from the powershell command prompt. But neither do I get any errors nor the script is loaded.

I have script in C:\temp\myFunction.ps1 (which has a method getMyName() )

I open the powershell command and navigate to this directory and execute

./myFunction.ps1

then there are no errors and return back to the next line in the prompt. But when I try to call the function getMyName - I get error getMyName is not recognised.

I have set the Execution-Policy to Unrestricted, I am running the powershell as Administrator

Upvotes: 0

Views: 5637

Answers (2)

CB.
CB.

Reputation: 60910

Try dot sourcing your script:

. .\myFunction.ps1 

Upvotes: 5

Saroop Trivedi
Saroop Trivedi

Reputation: 2265

It's basic problem of Powershell script. Set the Path where you physically saved your file and then execute the Powershell script. One more thing

1. start your command window run as admin.
2. set the Powershell script policy for execution.

Upvotes: 1

Related Questions