No Valid Module File Was Found

No valid module file was found in any module directory

In some cases, you may see the following error message when you try to import a PowerShell module:

Import-Module : The specified module 'Microsoft.Graph' was not loaded because
  no valid module file was found in any module directory.
At line:1 char:1
+ Import-Module Microsoft.Graph
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (Microsoft.Graph:String)
      [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.

Typically, two issues may cause this error message:

  1. The module is not installed on your system.
  2. Your PowerShell path is incorrect.

Take the following steps to find the root cause of the error message “no valid module file was found.”

Is the Module Installed On Your System?

PowerShell modules are installed in one of two folders:

Modules installed in admin mode are placed in the %ProgramFiles%\WindowsPowerShell\Modules folder.

Modules installed in user mode are placed in the %UserProfile%\Documents\WindowsPowerShell\Modules folder.

Please note that you can install PowerShell modules side-by-side in these two folders. However, if you install different versions side-by-side, you can really get into trouble. Read this article for more info on this.

Verify if the module you’re trying to import is in either of the two module folders.

You can also search for the installed modules on your system using the Get-Module CmdLet (looking for the Microsoft Graph module):

PS C:\> Get-Module -ListAvailable -Name *graph*

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   1.22.0     Microsoft.Graph
Script     1.22.0     Microsoft.Graph.Applications        {Add-MgApplicationKey, Add...
Script     1.22.0     Microsoft.Graph.Authentication      {Connect-MgGraph, Disconne...
Script     1.22.0     Microsoft.Graph.Bookings            {Get-MgBookingBusiness, Ge...
Script     1.22.0     Microsoft.Graph.Calendar            {Get-MgGroupCalendar, Get-...
Script     1.22.0     Microsoft.Graph.ChangeNotifications {Get-MgSubscription, Invok...
Script     1.22.0     Microsoft.Graph.CloudCommunications {Add-MgCommunicationCallLa...
Script     1.22.0     Microsoft.Graph.Compliance          {Add-MgComplianceEdiscover...
Script     1.22.0     Microsoft.Graph.CrossDeviceExper... {Get-MgUserActivity, Get-M...
Script     1.22.0     Microsoft.Graph.DeviceManagement    {Get-MgDeviceManagement, G...

(partial output)

Has Your PowerShell Path Been Modified?

If the module is installed correctly, the next step should be to verify if your PowerShell path has been modified.

The PowerShell path should look similar to the following:

PS C:\> $env:PSModulePath
C:\Program Files\WindowsPowerShell\Modules;

The path should include the user mode modules and the admin mode modules, as well as a third path in the system folder.

You can modify your PowerShell path via advanced system settings. Run the command “SystemPropertiesAdvanced” and click on “Environment Variables”:

Windows System Properties

Then select PSModulePath in System variables and click Edit:

Windows System Properties

You can then modify the PowerShell Path. Make sure to use system variables when editing the values:

Windows System Properties

When you have modified the PowerShell path, you must restart your PowerShell session before the changes take effect.

How to Avoid Complicated PowerShell Scripts

Let’s be clear: PowerShell is great for automation. But it stinks for ad-hoc support.

Fortunately, there’s a simple solution to allow first-level supporters to do their work quickly and efficiently:

Easy365Manager is a snap-in for AD Users & Computers that lets you do all daily Office 365 mailbox management directly from AD user properties.

This includes tasks like calendar delegation, that typically require complex PowerShell scripting:

Easy365Manager offers a lot of benefits that have made it an instant hit with companies and organizations worldwide:

  • Manage everything from one tool (no need for multiple, diverse web consoles).
  • Well-known and intuitive user interface (AD Users & Computers).
  • Eliminates attribute authority confusion (everything is managed in one place).
  • Enables the removal of Exchange on-premises.
  • Per-tenant licensing that supports unlimited users and admins.
  • Simple installation with no infrastructure changes and no learning curve.

Read more about Easy365Manager here and download the free 30-day trial.