【问题标题】:'Connect-MsolService' is not recognized as the name of a cmdlet'Connect-MsolService' 未被识别为 cmdlet 的名称
【发布时间】:2017-09-01 08:15:54
【问题描述】:
PSCommand commandToRun = new PSCommand();
commandToRun.AddCommand("Connect-MsolService");
commandToRun.AddParameter("Credential", new PSCredential(msolUsername, msolPassword));

powershell.Streams.ClearStreams();
powershell.Commands = commandToRun;
powershell.Invoke();

我试图在 Visual Studio 中运行上述代码并收到以下错误: “Connect-MsolService”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 但我能够从 Microsoft Azure Active Directory Module for Windows PowerShell 连接到 Msol 服务。请帮忙。

【问题讨论】:

  • 尝试使用Import-Module MSOnline导入模块

标签: powershell azure office365


【解决方案1】:

我必须按照这个顺序来做:

Install-Module MSOnline
Install-Module AzureAD
Import-Module AzureAD

【讨论】:

    【解决方案2】:

    所有指向 Azure Active Directory 连接页面的链接现在似乎都无效了。

    我也安装了旧版本的 Azure AD,这对我有用。 Install this.

    在提升的 PS 会话中运行这些:

    uninstall-module AzureAD  # this may or may not be needed
    install-module AzureAD
    install-module AzureADPreview
    install-module MSOnline
    

    然后我就可以登录并运行我需要的东西了。

    【讨论】:

      【解决方案3】:

      如果未正确加载适用于 Windows PowerShell 的 Azure Active Directory 模块,则可能会出现此问题。

      要解决此问题,请按以下步骤操作。
      1.在计算机上安装适用于 Windows PowerShell 的 Azure Active Directory 模块(如果尚未安装)。要安装适用于 Windows PowerShell 的 Azure Active Directory 模块,请访问以下 Microsoft 网站:
      Manage Azure AD using Windows PowerShell

      2.如果 MSOnline 模块不存在,请使用 Windows PowerShell 导入 MSOnline 模块。

      Import-Module MSOnline 
      

      完成后,我们可以使用该命令进行检查。

      PS C:\Users> Get-Module -ListAvailable -Name MSOnline*
      
      
          Directory: C:\windows\system32\WindowsPowerShell\v1.0\Modules
      
      
      ModuleType Version    Name                                ExportedCommands
      ---------- -------    ----                                ----------------
      Manifest   1.1.166.0  MSOnline                            {Get-MsolDevice, Remove-MsolDevice, Enable-MsolDevice, Disable-MsolDevice...}
      Manifest   1.1.166.0  MSOnlineExtended                    {Get-MsolDevice, Remove-MsolDevice, Enable-MsolDevice, Disable-MsolDevice...}
      

      关于这个问题的更多信息,请参考it


      更新

      我们应该将azure AD powershell导入VS 2015,我们可以添加工具并选择Azure AD powershell。

      【讨论】:

      • 它不工作..我可以使用我的 AAD 控制台运行 powershell MSOL 命令,但是当我尝试使用 Visual Studio(2015) 调试它时它抛出错误
      • Jason Ye - 如果您还知道其他解决方法,请告诉我?
      • 附加信息:PSVersion 4.0。我已将 MSOnline 和 MSOnlineExtented 文件从 System32/WindowsPowerShell/v1.0/Modules 复制到 SysWOW64/WindowsPowerShell/v1.0/Modules.. 但现在我遇到了另一个这样的错误:Automation.PSModule.dll' 或其一个依赖关系。试图加载格式不正确的程序。
      • 抱歉,我正在检查查询,并会尽快回复您。
      • @Aathira 看来我们应该将 azure ad powershell 导入这个工具,我已经更新了我的答案,请检查一下。
      【解决方案4】:

      以下对我有用:

      1. 卸载之前安装的“Microsoft Online Service Sign-in Assistant”和“Windows Azure Active Directory Module for Windows PowerShell”。
      2. 安装 64 位版本的“Microsoft Online Service Sign-in Assistant”和“Windows Azure Active Directory Module for Windows PowerShell”。 https://littletalk.wordpress.com/2013/09/23/install-and-configure-the-office-365-powershell-cmdlets/

      如果您收到以下错误为了安装适用于 Windows PowerShell 的 Windows Azure Active Directory 模块,您必须在此计算机上安装 Microsoft Online Services Sign-In Assistant 7.0 或更高版本,然后安装适用于 IT 专业人员的 Microsoft Online Services 登录助手 BETA: http://www.microsoft.com/en-us/download/details.aspx?id=39267

      1. 从源中复制名为 MSOnline 和 MSOnline Extended 的文件夹

      C:\Windows\System32\WindowsPowerShell\v1.0\Modules\

      到文件夹

      C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\

      https://stackoverflow.com/a/16018733/5810078.

      (但我实际上已经从

      复制了所有可能的文件

      C:\Windows\System32\WindowsPowerShell\v1.0\

      C:\Windows\SysWOW64\WindowsPowerShell\v1.0\

      (要复制,您需要更改该文件夹的安全权限))

      【讨论】:

        猜你喜欢
        • 2022-10-05
        • 2019-10-25
        • 2017-03-26
        • 2022-01-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-21
        相关资源
        最近更新 更多