首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在码头映像中安装AzureADPreview Powershell模块失败

在码头映像中安装AzureADPreview Powershell模块失败
EN

Stack Overflow用户
提问于 2022-06-15 15:00:53
回答 1查看 436关注 0票数 0

我正在尝试安装/使用AzureADPreview powershell模块来自动创建策略。

在VSCode中,我使用以下Dockerfile来处理dev容器:

代码语言:javascript
复制
 FROM mcr.microsoft.com/azure-powershell:latest

我想在这个容器中安装这个模块,并在里面做我所有的开发工作。

问题是,我似乎无法将模块安装在容器中。

我可以在我的主机(windows Box)上这样做:

代码语言:javascript
复制
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]:

当我在vscode容器中尝试相同的命令时,我会得到以下错误:

代码语言:javascript
复制
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.

编辑1

代码语言:javascript
复制
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.

以下是版本表:

代码语言:javascript
复制
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

下面是创建我所在容器的dockerfile:

代码语言:javascript
复制
 FROM mcr.microsoft.com/azure-powershell:latest
EN

回答 1

Stack Overflow用户

发布于 2022-06-16 05:48:59

导入模块:无法加载文件或程序集'System.Windows.Forms,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089‘。系统找不到指定的文件。

PowerShell cloudshell/mac在执行AzureAD模块时几乎没有限制。

目前,AzureAD.Standard.Preview (基于.NET标准的预览版)模块已经可用.该模块提供了与AzureAD相同的功能,它覆盖默认的Connect-AzureAD,因此它使用自定义身份验证机制CloudShell/Mac来避免您重新输入凭据。

为了解决这个问题,您可以使用下面的命令来安装AzureADStandardPreview模块。

这部分应该是可行的。

代码语言:javascript
复制
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

注意:确保在您的上安装了powershell 7.1.5/**Upgraded version**

这里需要注意的另一个更重要的事情是,来自 这个PowerShell论坛线程

AzureAD模块在PowerShell核心上不受支持。尝试使用Microsoft。它现在和将来将被支持跨平台。 遗留图形API将于2022年6月30日退役,虽然微软似乎决心将AzureAD和MSOL模块的具体情况保密,但一些功能(许可)肯定会在API被淘汰而转向MicrosoftGraph时停止工作。广泛的共识是,每个人都应该努力升级他们的脚本和模块,以使用Microsoft而不是AzureAD和MSOL模块。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72633672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档