The term 'import' is not recognized as the name of a cmdlet, function, script file, or operable program

less than a minute read 05-10-2024
The term 'import' is not recognized as the name of a cmdlet, function, script file, or operable program


"Import" Not Recognized? A PowerShell Import Problem Solved

Problem: You're trying to import a module or script file in your PowerShell session, but you encounter the frustrating error: "The term 'import' is not recognized as the name of a cmdlet, function, script file, or operable program."

Understanding the Error:

This error message indicates that PowerShell is unable to locate or execute an 'import' command. You're likely trying to import a module or script file, but the syntax you're using is incorrect. PowerShell doesn't have a command named "import". Instead, you need to use the Import-Module cmdlet.

Scenario and Code:

Imagine you want to use the ActiveDirectory module in your PowerShell session. You might incorrectly try to import it like this:

import ActiveDirectory

This will throw the error we've been discussing.

The Solution:

To import modules or script files correctly, use the Import-Module cmdlet:

Import-Module ActiveDirectory

Additional Insights and Examples:

  • Module Paths: Import-Module will search for modules in the default module paths defined by PowerShell. If your module is located elsewhere, you can specify the full path.

    Import-Module -Path "C:\MyModules\CustomModule.psm1" 
    
  • Importing Script Files: You can also import script files using Import-Module.

    Import-Module -Path "C:\MyScripts\MyScript.ps1"
    
  • Verifying Module Import: To check if a module is already loaded, use Get-Module:

    Get-Module -Name ActiveDirectory
    

Key Takeaways:

  1. PowerShell does not use "import"; it uses the Import-Module cmdlet.
  2. You can specify the path to the module or script file if it's not in the default location.
  3. Use Get-Module to verify if a module is already imported.

Resources:

By understanding these concepts and using the correct syntax, you can effectively import modules and script files in your PowerShell sessions.