PowerShell The term is not recognized as cmdlet function script file or operable program

PowershellCmdPowershell 2.0Command Prompt

Powershell Problem Overview


I am implementing a script in powershell and getting the below error. The sceen shot is there exactly what I entered and the resulting error.

enter image description here

At this path there is file Get-NetworkStatistics.ps1 which I got from Technet Gallery. I am following the steps from it, though there are errors.

Powershell Solutions


Solution 1 - Powershell

You first have to 'dot' source the script, so for you :

. .\Get-NetworkStatistics.ps1

The first 'dot' asks PowerShell to load the script file into your PowerShell environment, not to start it. You should also use set-ExecutionPolicy Unrestricted or set-ExecutionPolicy AllSigned see(the Execution Policy instructions).

Solution 2 - Powershell

For the benefit of searchers, there is another way you can produce this error message - by missing the $ off the script block name when calling it.

e.g. I had a script block like so:

$qa = {
    param($question, $answer)
    Write-Host "Question = $question, Answer = $answer"
}

I tried calling it using:

&qa -question "Do you like powershell?" -answer "Yes!"

But that errored. The correct way was:

&$qa -question "Do you like powershell?" -answer "Yes!"

Solution 3 - Powershell

Yet another way this error message can occur...

If PowerShell is open in a directory other than the target file, e.g.:

If someScript.ps1 is located here: C:\SlowLearner\some_missing_path\someScript.ps1, then C:\SlowLearner>. ./someScript.ps1 wont work.

In that case, navigate to the path: cd some_missing_path then this would work:

C:\SlowLearner\some_missing_path>. ./someScript.ps1

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3505712View Question on Stackoverflow
Solution 1 - PowershellJPBlancView Answer on Stackoverflow
Solution 2 - PowershellJsAndDotNetView Answer on Stackoverflow
Solution 3 - PowershellSlowLearnerView Answer on Stackoverflow