The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded
Asked Answered
S

2

5

I have used Az module in powershell script which is getting executed from powershell core but getting error while executing the script from application (.Net core SDK 2.1).

$VMExistanceCheck = Get-azVM -ResourceGroupName $VMResourceGroup -Name $NewComputerName -ErrorAction SilentlyContinue

I checked that Az.Compute module had been imported there.

I added Import-Module Az.compute -verbose -force inside the script also.

I got the following error while the script is getting invoked from application using runspace(System.Management.Automation, Version=6.1.0.0):

System.Management.Automation.RuntimeException: The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded. For more information, run 'Import-Module Az.Compute'. ---> System.Management.Automation.CommandNotFoundException: The 'Get-azVM' command was found in the module 'Az.Compute', but the module could not be loaded. For more information, run 'Import-Module Az.Compute'.

'Get-Module -ListAvailable ' shows that Az.Compute module is avilable but while the command 'import-module Az.Compute' is executed using Powershell 6, nothing is importing.

Startling answered 26/3, 2019 at 13:2 Comment(8)
You can provide more details about what error do you get? If all the Azure PowerShell cannot execute? And do you log in before you execute the Azure PowerShell?Atomic
Can you post complete error exception message >Swirly
Do you set the execution policy for your local machine?Atomic
yes. I have already set it to unrestrictedStartling
Is it only Az.compute module can't be used?Atomic
Add-AzAccount and Login-AzAccount are executing inside the script before the 'Get-azVM' commandStartling
You can try to import the Az.compute module before running the script.Atomic
'Import-Module Az.compute -verbose -force' is there at the beginning of the script.I had also added 'Import-Module -Name Az.Accounts ' which is working fine.Startling
S
1

I checked the log of PowerShellCore/Operational from Event viewer and found the following error:

Error Message = Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=9.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) Fully Qualified Error ID = System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

I have installed Microsoft.WindowsAzure.Storage and finally the powershell script is getting invoked and the Get-AZVM command is successfully getting executed.

Startling answered 4/4, 2019 at 11:38 Comment(1)
This package has been deprecated. See nuget.org/packages/WindowsAzure.Storage . It appears to have been replaced by multiple packages Microsoft.Azure.Storage.Blob, Microsoft.Azure.Storage.File, Microsoft.Azure.Storage.Queue, and Microsoft.Azure.Storage.Common.Hangeron
S
6
Install-Module -Name Az -AllowClobber -Scope CurrentUser

Run that command. Restart Powershell. Run import-module az.compute again

Smarm answered 15/5, 2019 at 15:41 Comment(0)
S
1

I checked the log of PowerShellCore/Operational from Event viewer and found the following error:

Error Message = Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=9.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621) Fully Qualified Error ID = System.IO.FileLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

I have installed Microsoft.WindowsAzure.Storage and finally the powershell script is getting invoked and the Get-AZVM command is successfully getting executed.

Startling answered 4/4, 2019 at 11:38 Comment(1)
This package has been deprecated. See nuget.org/packages/WindowsAzure.Storage . It appears to have been replaced by multiple packages Microsoft.Azure.Storage.Blob, Microsoft.Azure.Storage.File, Microsoft.Azure.Storage.Queue, and Microsoft.Azure.Storage.Common.Hangeron

© 2022 - 2024 — McMap. All rights reserved.