The ‘New-AzSynapseWorkspace’ command was found in the module Az.Synapse’, but the module could not be loaded

In this azure tutorial, we will discuss how to fix the error, The ‘New-AzSynapseWorkspace’ command was found in the module Az.Synapse’, but the module could not be loadedwhich I got while trying to create an Azure Synapse Analytics Workspace using PowerShell in Azure.

The ‘New-AzSynapseWorkspace’ command was found in the module Az.Synapse’, but the module could not be loaded

Recently, I was trying to execute the below Azure PowerShell script to create the Workspace, but I got the above error.

$SWN = 'BuildWP123'
$resourceGrp = 'test690'
$StorageAN ='testgact'
$SNFile4 = 'testfile'
$UserSQL = 'user123'
$PasswordSQL = 'Password123'
$Region = 'West US'

$TCred = New-Object -TypeName System.Management.Automation.PSCredential ($UserSQL, (ConvertTo-SecureString $PasswordSQL -AsPlainText -Force))

$wpParams = @{
  Name = $SWN
  ResourceGroupName = $resourceGrp
  DefaultDataLakeStorageAccountName = $StorageAN
  DefaultDataLakeStorageFilesystem = $SNFile4
  SqlAdministratorLoginCredential = $TCred
  Location = $Region
}
New-AzSynapseWorkspace @wpParams

After executing the above script, I got the below error.

The 'New-AzSynapseWorkspace' command was found

Below is the complete error message that I got

New-AzSynapseWorkspace: The ‘New-AzSynapseWorkspace’ command was found in the module
‘Az.Synapse’, but the module could not be loaded. For more information, run
‘Import-Module Az.Synapse’.
At line:18 char:1

  • New-AzSynapseWorkspace @wpParams
  • ~~~~~~
    • CategoryInfo : ObjectNotFound: (New-AzSynapseWorkspace:String) [], Com
      mandNotFoundException
    • FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

The ‘New-AzSynapseWorkspace’ command was found in the module Az.Synapse’, but the module could not be loaded [Solved]

To fix this error, I have followed the below steps.

  1. Run the below command to import the Az.Synapse
Import-Module Az.Synapse
The 'New-AzSynapseWorkspace' command was found in the module Az.Synapse'

But after running, the above Azure PowerShell cmd, I got the below error

” C:\Program Files\WindowsPowerShell\Modules\Az.Synapse\1.0.0\Az.Synapse.psm1 : This
module requires Az.Accounts version 2.7.1. An earlier version of Az.Accounts is
imported in the current PowerShell session
. Please open a new session before
importing this module. This error could indicate that multiple incompatible versions
of the Azure PowerShell cmdlets are installed on your system. Please see
https://aka.ms/azps-version-error for troubleshooting information.
At line:1 char:1

  • Import-Module Az.Synapse
  • ~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Az.Sy
      napse.psm1

Import-Module : The module to process ‘Az.Synapse.psm1’, listed in field
‘NestedModules’ of module manifest ‘C:\Program
Files\WindowsPowerShell\Modules\Az.Synapse\1.0.0\Az.Synapse.psd1′ was not processed
because no valid module was found in any module directory.
At line:1 char:1

  • Import-Module Az.Synapse
  • ~~~~~~~~
    • CategoryInfo : ResourceUnavailable: (Az.Synapse:String) [Import-Module
      ], PSInvalidOperationException
    • FullyQualifiedErrorId : Modules_ModuleFileNotFound,Microsoft.PowerShell.Command
      s.ImportModuleCommand “

Now, to fix this issue I tried installing Az.Accounts version 2.7.1 using the below Azure PowerShell command.

Install-Module -Name Az.Accounts -RequiredVersion 2.7.1

Note: Before installing Az.Accounts version 2.7.1. Try using a new PowerShell session to import the Az.Synapse module.

Then I have opened one more session of PowerShell and tried importing the Az.Synapse module again using the below command

Import-Module Az.Synapse

This time it was executed successfully without any issue.

The 'New-AzSynapseWorkspace' command was found in the module Az.Synapse error

Then, I ran the Azure PowerShell script to create the Workspace again and this time it executed successfully, and the Azure Synapse Analytics Workspace got created without any issue.

You may also like following the below articles

Wrapping Up

In this article, we have discussed how to fix the error “The ‘New-AzSynapseWorkspace’ command was found in the module Az.Synapse’, but the module could not be loaded“. Hope it helped you to fix your issue as well.