Skip to main content
added 17 characters in body
Source Link
creatiive
  • 1.1k
  • 2
  • 24
  • 50

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

The following script file resolved my issue and can be run from the command line fine;

Import-Module 'C:\My Path\script.ps1'
.MyStartFunction C:\My Path\script.ps1# calls other functions

powershell "& "'C:\My Path\AboveScriptFile.ps1'"

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

The following script file resolved my issue and can be run from the command line fine;

Import-Module 'C:\My Path\script.ps1'
. C:\My Path\script.ps1

powershell "& "'C:\My Path\AboveScriptFile.ps1'"

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

The following script file resolved my issue and can be run from the command line fine;

Import-Module 'C:\My Path\script.ps1'
MyStartFunction  # calls other functions

powershell "& "'C:\My Path\AboveScriptFile.ps1'"
added 168 characters in body
Source Link
creatiive
  • 1.1k
  • 2
  • 24
  • 50

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

The following script file resolved my issue and can be run from the command line fine;

Import-Module 'C:\My Path\script.ps1'
. C:\My Path\script.ps1

powershell "& "'C:\My Path\AboveScriptFile.ps1'"

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2

The following script file resolved my issue and can be run from the command line fine;

Import-Module 'C:\My Path\script.ps1'
. C:\My Path\script.ps1

powershell "& "'C:\My Path\AboveScriptFile.ps1'"
Source Link
creatiive
  • 1.1k
  • 2
  • 24
  • 50

Powershell functions not recognized when calling from command line

I have a simple problem. My powershell script contains a couple of functions and the script calls these functions no problem.

However, when I try to run powershell from the command line to execute my script, I get the error;

The term 'MyFunction' is not recognized as the name of a cmdlet....'

Everywhere tells me I need to run my script like so from the command line for it to work;

powershell "& "'C:\My Path\script.ps1'"

This runs the script but the functions still do not work. I get the errors wherever my script calls one of the functions. What am I doing wrong? I have even gone as far as creating another script with a single line in it that just says;

. C:\My Path\script.ps1

This again works fine but then when run through the command line it fails with the same errors. Any help with this would be greatly appreciated!

EDIT: The function is defined like this;

function MyFunction ($id1, $id2) {
    ....
}

And it is called like this;

MyFunction $var1 $var2