Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module fails import on Azure Automation account #25

Closed
LeoniSantos opened this issue Feb 19, 2019 · 19 comments
Closed

Module fails import on Azure Automation account #25

LeoniSantos opened this issue Feb 19, 2019 · 19 comments

Comments

@LeoniSantos
Copy link

Hello,

I am trying to use this module in a Azure automation account with a runbook to automate some daily tasks, but the same fails to import, i have a premier support tickets openned, but for now i had no lucky, do you know if this should works there? if not the reason why it is not compatible?

Also if fails to work the only possible solution is using the intune powershell samples? that are basically REST API calls?

Thank you

image

@chwilfing
Copy link

Have the same problem with the module being loaded in the powershell VSCode module. Same error as in the module load:

Import-Module : Mindestens ein Typ in der Assembly kann nicht geladen werden. Rufen Sie die LoaderExceptions-Eigenschaft ab, wenn Sie weitere Informationen benötigen.
At line:1 char:1

  • Import-Module microsoft.graph.intune
  •   + CategoryInfo          : NotSpecified: (:) [Import-Module], ReflectionTypeLoadException
      + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
    
    

(sorry for german error, it says something like - an assembly cannot be loaded and you should retrieve the LoaderException property to get a detailed error)

@HackershubNL
Copy link

Ran into the same issue but after poking around in the LoaderExceptions, it turned out that two assemblies were missing.

Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.AspNet.SignalR.Client, Version=2.2.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

Could not load file or assembly 'Microsoft.Practices.ServiceLocation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

It is a bit of a hack job and not very efficient but it runs with the following code. It will download the assemblies and the SDK, load the assemblies and then imports the module.

wget -uri "https://github.com/Microsoft/Intune-PowerShell-SDK/releases/download/1902/Intune-PowerShell-SDK_v6.1902.00758.0001-release-97194499-net471.zip" -outfile "Intune-PowerShell-SDK.zip"
wget -uri "https://www.nuget.org/api/v2/package/Microsoft.AspNet.SignalR.Client/2.2.1.0" -outfile "Microsoft.AspNet.SignalR.Client.zip"
wget -uri "https://www.nuget.org/api/v2/package/Cquential.Microsoft.Practices.ServiceLocation/1.0.0" -outfile "Cquential.Microsoft.Practices.ServiceLocation.zip"

Unblock-File Intune-PowerShell-SDK.zip
Unblock-File Microsoft.AspNet.SignalR.Client.zip
Unblock-File Cquential.Microsoft.Practices.ServiceLocation.zip

Expand-Archive Intune-PowerShell-SDK.zip
Expand-Archive Microsoft.AspNet.SignalR.Client.zip
Expand-Archive Cquential.Microsoft.Practices.ServiceLocation.zip

Add-Type -Path .\Cquential.Microsoft.Practices.ServiceLocation\lib\net35\Microsoft.Practices.ServiceLocation.dll
Add-Type -Path .\Microsoft.AspNet.SignalR.Client\lib\net45\Microsoft.AspNet.SignalR.Client.dll

try
{
  Import-Module .\Intune-PowerShell-SDK\drop\outputs\build\Release\net471\Microsoft.Graph.Intune.psd1 -Scope Local -Force
}
catch
{
  $_.Exception.GetBaseException().LoaderExceptions
}

$login = Get-AutomationPSCredential -Name 'YourCredentialName'

$connection = Connect-MSGraph -PSCredential $login

Get-IntuneManagedDevice

@HackershubNL
Copy link

Created a patched version which can be loaded into a runbook using Import-Module. It still refuses to be imported into an Automation Account though.
https://github.com/HackershubNL/Intune-PowerShell-SDK/releases/tag/1902-AzAutomationFix%60

wget -uri "https://github.com/HackershubNL/Intune-PowerShell-SDK/releases/download/1902-AzAutomationFix%60/Microsoft.Graph.Intune.zip" -outfile "Microsoft.Graph.Intune.zip"

Unblock-File Microsoft.Graph.Intune.zip

Expand-Archive Microsoft.Graph.Intune.zip

Import-Module .\Microsoft.Graph.Intune\Microsoft.Graph.Intune.psd1 -Scope Local -Force

@LeoniSantos
Copy link
Author

Sounds really great!! I will test it today, for new automations this will be really great, i had to recreated the functions using just Rest API for last job and it was a lot of work.

Thanks!!!

@lundholmster
Copy link

Hi, I'm trying to get this working as well. Could we expect a fix for the Azure Automation import?
Hackershubnl, I've tried your patch but it seems to fail as well.

Import-Module : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more 
information.
At line:18 char:1
+ Import-Module .\Microsoft.Graph.Intune\Microsoft.Graph.Intune.psd1 -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], ReflectionTypeLoadException
    + FullyQualifiedErrorId : 
System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand

Thanks!

@davefalkus
Copy link
Collaborator

Hi all,

We are aware of the failure of importing the module into Azure Automation, we are looking into it.

Dave

@HackershubNL
Copy link

Through the LoaderExceptions, found out that it suddenly requires the SignalR.Client version 2.4.0 .
Updated my fork to reflect this and with a new release.
https://github.com/HackershubNL/Intune-PowerShell-SDK/releases

You can use the following snippet to import it:

wget -uri "https://github.com/HackershubNL/Intune-PowerShell-SDK/releases/download/1902-AzAutomationFixPlusUpdatedDependencies/Microsoft.Graph.Intune.zip" -outfile "Microsoft.Graph.Intune.zip"

Unblock-File Microsoft.Graph.Intune.zip

Expand-Archive Microsoft.Graph.Intune.zip

Import-Module .\Microsoft.Graph.Intune\Microsoft.Graph.Intune.psd1 -Scope Local -Force

I've tested it with a brand new Automation Account and no other modules are required.

@bmkaiser
Copy link

bmkaiser commented May 20, 2019

I am having a similar issue, but am not using Azure Automation.

PS C:\WINDOWS\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.503
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.503
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\WINDOWS\system32> Get-Module -Name Microsoft.Graph.Intune -ListAvailable


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     6.1902.... Microsoft.Graph.Intune              {New-ActivityHistoryItemObject, New-AlertObject, New-Alert...


PS C:\WINDOWS\system32> Import-Module -Name Microsoft.Graph.Intune
Import-Module : Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more
information.
At line:1 char:1
+ Import-Module -Name Microsoft.Graph.Intune
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], ReflectionTypeLoadException
    + FullyQualifiedErrorId : System.Reflection.ReflectionTypeLoadException,Microsoft.PowerShell.Commands.ImportModule
   Command

PS C:\WINDOWS\system32> $Error[0].Exception.GetBaseException().loaderexceptions
Could not load file or assembly 'Microsoft.WindowsAzure.Storage, Version=6.2.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

@HackershubNL
Copy link

Microsoft.WindowsAzure.Storage seems to be Azure.Storage module according to the Microsoft docs. Maybe try installing it with:

Install-Module Azure.Storage

And try again. When you get another exception keep going through the LoaderExceptions to see which one is missing, find the module, install it and try again :)

@bmkaiser
Copy link

Thank you, @HackershubNL. I retried after installing Azure.Storage and its dependency AzureRM.Profile, but the error is the same when trying to import the Microsoft.Graph.Intune module. Still has an issue with the Microsoft.WindowsAzure.Storage assembly

@HackershubNL
Copy link

That's a bit of odd issue. Since it is looking for version 6.2.0 another debugging option would be to download the DLL from the NuGet gallery and importing it by hand:

  • Download .nupkg file from https://www.nuget.org/api/v2/package/WindowsAzure.Storage/6.2.0
  • Unblock the file otherwise the DLL won't run
  • Change file extension to .zip
  • Extract the DLL from windowsazure.storage.6.2.0.zip\lib\net40\
  • Import into PowerShell with: Add-Type -Path .\Microsoft.WindowsAzure.Storage.dll
  • Import Intune module

@ThomasKur
Copy link

@davefalkus already a plan when this will be resolved or should we still implement some workarounds?

@rohitramu
Copy link
Contributor

rohitramu commented Jun 11, 2019

I'm working with the Azure Automation team to find a solution. I'm not sure when we will get this fixed, but we're actively working on this.

In the meantime, I've put some snippets together (thanks @HackershubNL!) to workaround the issue while still using the version of the Intune PowerShell SDK in the PowerShell Gallery:

# Get SignalR.Client
wget -uri "https://www.nuget.org/api/v2/package/Microsoft.AspNet.SignalR.Client/2.4.0.0" -outfile "Microsoft.AspNet.SignalR.Client.zip"
Unblock-File Microsoft.AspNet.SignalR.Client.zip
Expand-Archive Microsoft.AspNet.SignalR.Client.zip
Add-Type -Path .\Microsoft.AspNet.SignalR.Client\lib\net45\Microsoft.AspNet.SignalR.Client.dll

# Get Practices.ServiceLocation
wget -uri "https://www.nuget.org/api/v2/package/Cquential.Microsoft.Practices.ServiceLocation/1.0.0" -outfile "Cquential.Microsoft.Practices.ServiceLocation.zip"
Unblock-File Cquential.Microsoft.Practices.ServiceLocation.zip
Expand-Archive Cquential.Microsoft.Practices.ServiceLocation.zip
Add-Type -Path .\Cquential.Microsoft.Practices.ServiceLocation\lib\net35\Microsoft.Practices.ServiceLocation.dll

# Install the module
Write-Host 'Installing...'
Install-Module Microsoft.Graph.Intune -Force -AcceptLicense

# Import the module
Write-Host 'Importing...'
try {
    Import-Module Microsoft.Graph.Intune
} catch [System.Reflection.ReflectionTypeLoadException] {
    $_.Exception.GetBaseException().loaderexceptions
    exit
}

# Log into test tenant
Write-Host 'Logging in...'
$creds = Get-AutomationPSCredential -Name 'your-credential-name' # To create credentials in Azure Automation: https://docs.microsoft.com/en-us/azure/automation/shared-resources/credentials#creating-a-new-credential-asset
Connect-MSGraph -PSCredential $creds

# Run a simple cmdlet (no network traffic)
Write-Host 'Get current MSGraph environment parameters'
Get-MSGraphEnvironment

# Make a call to Microsoft Graph using the cmdlets
Write-Host 'List all mobile apps'
Get-IntuneMobileApp

UPDATE: @bmcder rightly mentioned that the "PowerShellGet" module needs to be installed/updated in Azure Automation. This module depends on the "PackageManagement" module, so this needs to be installed first. These modules can be installed into Azure Automation from the Modules Gallery.
More about installing Azure Automation modules: https://docs.microsoft.com/en-us/azure/automation/automation-runbook-gallery#modules-in-powershell-gallery

@bmcder
Copy link

bmcder commented Jun 19, 2019

The proposed workaround will not work to import the module into Azure Automation due to the lack of NuGet in that environment.

@rohitramu
Copy link
Contributor

rohitramu commented Jun 19, 2019

@bmcder The NuGet executable should not be required, since we are using the wget cmdlet to download the package and the Expand-Archive cmdlet to extract the needed files.

Could you please share the error you are seeing?

@bmcder
Copy link

bmcder commented Jun 19, 2019

Thanks Rohit for making me re-check this.

It was originally failing with an error on this line...

Install-Module Microsoft.Graph.Intune -Force -AcceptLicense

...stating that -AcceptLicense was an unknown parameter. On removing that, I received a NuGet related error running the same line (apologies I don't have a copy of that error).

Today I engaged my brain and checked the history of the Install-Module command to learn that the -AcceptLicense switch was added in PowerShell v6.

So I imported the latest PowerShellGet module (today this is version 2.1.5) into the Automation Account, which required I first import the PackageManagement module (today this is version 1.4.2). After that I added the -AcceptLicense switch back in and all was good :)

@rohitramu
Copy link
Contributor

Thanks @bmcder for sharing the fix for your error! Good to know that -AcceptLicense is only available in PowerShell v6 and above.

@WithHolm
Copy link

WithHolm commented Jul 4, 2019

FYI, this is avalible in nuget and can be downloaded with find-module "microsoft.graph.intune"|install-module" assuming you have powershell 5 or newer.

In Azure Automation this can be selected if you use the module gallery in your azure automation account
bilde

@rohitramu
Copy link
Contributor

I'm very pleased to say that we were able to work with the Azure Automation team to find a solution. This issue is now fixed in the latest version (6.1907.1.0) of the module on PowerShell Gallery!

I was able to run this script in Azure Automation:

# Import the module
Write-Host 'Installing...'
Install-Module Microsoft.Graph.Intune -Force -AcceptLicense

# Log into test tenant
Write-Host 'Logging in...'
$creds = Get-AutomationPSCredential -Name 'your-credential-name' # To create credentials in Azure Automation: https://docs.microsoft.com/en-us/azure/automation/shared-resources/credentials#creating-a-new-credential-asset
Connect-MSGraph -PSCredential $creds

# Run a simple cmdlet (no network traffic)
Write-Host 'Get current MSGraph environment parameters'
Get-MSGraphEnvironment

# Make a call to Microsoft Graph using the cmdlets
Write-Host 'List all mobile apps'
Get-IntuneMobileApp

I will close this now, but please feel free to keep discussing if there are any more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants