[英]Installing AzureADPreview Powershell module fails in docker image
I'm trying to install / use the AzureADPreview powershell module to automate the creation of a policy.我正在尝试安装/使用 AzureADPreview powershell 模块来自动创建策略。
I am using the following Dockerfile for my devcontainer in VSCode:我在 VSCode 中为我的 devcontainer 使用以下 Dockerfile:
FROM mcr.microsoft.com/azure-powershell:latest
I'd like to install the module in this container and do all my dev work inside.我想在这个容器中安装模块并在里面完成我所有的开发工作。
Problem is I can't seem to get the module installed in the container.问题是我似乎无法将模块安装在容器中。
I am able to do this on my HOST machine (windows box):我可以在我的主机(windows box)上做到这一点:
PS C:\Users\me\Documents\src\test> Get-Module azureadpreview -ListAvailable
Directory: C:\Users\me\Documents\PowerShell\Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Binary 2.0.2.149 AzureADPreview Desk
PS C:\Users\me\Documents\src\test> Import-Module AzureADPreview -RequiredVersion 2.0.2.149
PS C:\Users\me\Documents\src\test> Get-Command -Module AzureADPreview -Name Get-AzureADPo*
CommandType Name Version Source
----------- ---- ------- ------
Cmdlet Get-AzureADPolicy 2.0.2.149 AzureADPreview
Cmdlet Get-AzureADPolicyAppliedObject 2.0.2.149 AzureADPreview
PS C:\Users\me\Documents\src\test> New-AzureADPolicy
cmdlet New-AzureADPolicy at command pipeline position 1
Supply values for the following parameters:
Definition[0]:
When i try the same commands in the vscode container, I get this error:当我在 vscode 容器中尝试相同的命令时,我收到此错误:
PS /workspaces/test> Install-Module AzureADPreview
PS /workspaces/test> Get-Module azureadpreview -ListAvailable
Directory: /root/.local/share/powershell/Modules
ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Binary 2.0.2.149 AzureADPreview Desk
PS /workspaces/test> Import-Module AzureADPreview -RequiredVersion 2.0.2.149
Import-Module: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
EDIT 1编辑 1
root@662a90ff1b93:/workspaces/test# pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /workspaces/test> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
PS /workspaces/test> Register-PackageSource -Trusted -ProviderName 'PowerShellGet' -Name 'Posh Test Gallery' -Location 'https://www.poshtestgallery.com/api/v2'
Register-PackageSource: The specified Uri 'https://www.poshtestgallery.com/api/v2' for parameter 'Location' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.
Here's the version table:这是版本表:
PS /workspaces/test> $PSVersionTable
Name Value
---- -----
PSVersion 7.2.4
PSEdition Core
GitCommitId 7.2.4
OS Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
And here's the dockerfile that creates this container I'm in:这是创建我所在的容器的 dockerfile:
FROM mcr.microsoft.com/azure-powershell:latest
Import-Module: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
导入模块:无法加载文件或程序集“System.Windows.Forms,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089”。 The system cannot find the file specified.
该系统找不到指定的文件。
PowerShell cloudshell/mac runs with few limitations when executing AzureAD modules执行 AzureAD 模块时,PowerShell cloudshell/mac 运行几乎没有限制
Currently, AzureAD.Standard.Preview
, a preview version of .NET Standard-based, module is available.目前,
AzureAD.Standard.Preview
是一个基于 .NET Standard 的预览版模块可用。 This module provides the same functionality as AzureAD
that overrides the default Connect-AzureAD
so that it uses the custom authentication mechanism CloudShell/Mac uses to avoid you having to re-enter credentials.此模块提供与覆盖默认
Connect-AzureAD
AzureAD
的功能,因此它使用 CloudShell/Mac 使用的自定义身份验证机制来避免您必须重新输入凭据。
For Workaround you can use the below command to install the AzureADStandardPreview
module.对于解决方法,您可以使用以下命令安装
AzureADStandardPreview
模块。
This Partially should works.这部分应该有效。
Register-PackageSource -Trusted -ProviderName 'PowerShellGet' -Name 'Posh Test Gallery' -Location https://www.poshtestgallery.com/api/v2/'
Install-Module AzureAD.Standard.Preview
import-Module AzureAD.Standard.Preview
Note : Make sure you got powershell 7.1.5/ Upgraded version
installed on your mac注意:确保您的 Mac 上安装了 powershell 7.1.5/
Upgraded version
Another more Important things to notice here is .......这里需要注意的另一个更重要的事情是......
The AzureAD module won't be supported on PowerShell Core.
PowerShell Core 不支持 AzureAD 模块。 Try using the Microsoft Graph SDK.
尝试使用 Microsoft Graph SDK。 It is and will be supported cross-platform.
它现在并且将得到跨平台的支持。
The legacy Graph APIs are being retired on 30th June 2022 and while Microsoft seem determined to keep exactly what's going to happen to the AzureAD and MSOL modules a secret, some functionality (licensing) will definitely stop working when the APIs are retired in favour of Microsoft Graph.
旧版 Graph API 将于 2022 年 6 月 30 日停用,虽然微软似乎决心对 AzureAD 和 MSOL 模块将要发生的事情保密,但当 API 被微软淘汰时,某些功能(许可)肯定会停止工作图形。 The broad consensus is that everyone should be working to upgrade their scripts and modules to use the Microsoft Graph SDK instead of the AzureAD and MSOL modules.
广泛的共识是,每个人都应该努力升级他们的脚本和模块,以使用 Microsoft Graph SDK 而不是 AzureAD 和 MSOL 模块。
Reference : https://forums.powershell.org/t/azuread-module-installed-on-mac-but-connect-azuread-is-not-recognized/16062/7参考: https ://forums.powershell.org/t/azuread-module-installed-on-mac-but-connect-azuread-is-not-recognized/16062/7
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.