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.

SRoy
  • 61
  • 1
  • 1
  • 6

2 Answers2

6
Install-Module -Name Az -AllowClobber -Scope CurrentUser

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

hansotto
  • 61
  • 2
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.

SRoy
  • 61
  • 1
  • 1
  • 6
  • 1
    This package has been deprecated. See https://www.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. – Llama D'Attore May 20 '20 at 08:14