Skip to content

Powershell 7.0 + AzureAD #544

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

Closed
johlindr opened this issue Sep 29, 2020 · 4 comments
Closed

Powershell 7.0 + AzureAD #544

johlindr opened this issue Sep 29, 2020 · 4 comments

Comments

@johlindr
Copy link

There seems to be some issue with the PS 7.0 and Azure AD module, (AzureAD module installed using dependency management)

Import-Module AzureAD -UseWindowsPowerShell
$requiredResourceAccess = New-Object -TypeName "Microsoft.Open.AzureAD.Model.RequiredResourceAccess"
$resourceAccess = New-Object -TypeName "Microsoft.Open.AzureAD.Model.ResourceAccess"

@{
'Az' = '4.'
'AzureAD' = '2.
'
}

The above will fail with the following Exception:

[Error] ERROR: Cannot find type [Microsoft.Open.AzureAD.Model.RequiredResourceAccess]: verify that the assembly containing this type is loaded.

[Error] ERROR: Cannot find type [Microsoft.Open.AzureAD.Model.ResourceAccess]: verify that the assembly containing this type is loaded.

The sample is simplified and was tested on a vanilla function to eliminate env. specific problems. Interesting is that rest of AzureAD module functions I've tested works appropriately (Connect-AzureAD etc.)

@kilasuit
Copy link

Can you not do what you want with the *-AzAD* cmdlets (which are included in the Az.Resources module which is available in the functions runtime?

@johlindr
Copy link
Author

johlindr commented Sep 29, 2020

Can you not do what you want with the *-AzAD* cmdlets (which are included in the Az.Resources module which is available in the functions runtime?

No not really, this is part of a larger AAD automation case...

How would you set the ResourceAccess on the Application using Az module, can't find anything on this ?

@AnatoliB
Copy link
Contributor

AnatoliB commented Oct 1, 2020

@johlindr When a module is imported with the -UseWindowsPowerShell switch, it is in fact loaded into a separate powershell.exe process, with just a thin proxy in the original PS session. So, the AzureAD assemblies you are trying to use are also loaded into the powershell.exe process and not available in the worker process. The proxy in the original PS session makes all the exported commands available, but not the .NET types.

Workarounds:

  • Wrap the code that relies on these assemblies into a separate module. This module should target Windows PowerShell 5.1. From your PowerShell function, load this module with the -UseWindowsPowerShell switch.
  • Pass the PS code relying on AzureAD to an explicitly spawned powershell.exe (see Using AzureAD module requires an awkward workaround #232 (comment)). This workaround is quite cumbersome, I would recommend the previous one if possible.

Also, consider using the Microsoft Graph module: it works in PowerShell 7 and it may be able to address you scenario.

@johlindr
Copy link
Author

johlindr commented Oct 6, 2020

Thanks AnatoliB, this behavior seems logical to how the -UseWindowsPowershell works, bit troublesome indeed, should be more straight forward. Hopefully the AzureAD module would be ported to PS core at some point.

I'll give your suggestion a go.

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

No branches or pull requests

3 participants