2017-04-06 82 views
0
 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代码运行,并得到以下错误: “连接-MsolService”这个词是不被视为cmdlet的名称,函数,脚本文件或可操作程序。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 但是我能够从Microsoft Azure Active Directory模块(用于Windows PowerShell)连接到Msol服务。请帮忙。“连接-MsolService”没有被识别为cmdlet的名称

+1

尝试使用导入模块'导入模块MSOnline' –

回答

2

继为我工作:

  1. 卸载以前安装的“微软在线服务登录助手”和“适用于Windows PowerShell的Windows Azure Active Directory模块”。
  2. 安装64位版本的“Microsoft Online Service登录助手”和“Windows PowerShell的Windows Azure Active Directory模块”。 https://littletalk.wordpress.com/2013/09/23/install-and-configure-the-office-365-powershell-cmdlets/

如果您收到以下错误为了安装的Windows Azure Active Directory模块用于Windows PowerShell中,您必须安装Microsoft在线服务登录在已安装的这台电脑上Assistant版本7.0或更高版本,然后安装微软在线服务登录助手为IT专业人员BETA: http://www.microsoft.com/en-us/download/details.aspx?id=39267

  • 复制称为MSOnline和MSOnline文件夹从源扩展
  • C:\ Windows \ System32 \ WindowsPowerShell \ v1。0 \模块\

    文件夹

    C:\ WINDOWS \ Syswow64资料\ WindowsPowerShell \ V1.0 \模块\

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

    (但其实我已经从

    ç复制所有可能的文件:\ WINDOWS \ SYSTEM32 \ WindowsPowerShell \ V1.0 \

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

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

    1

    如果未正确加载用于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


    更新

    我们应导入蔚蓝AD PowerShell来VS 2015年,我们可以添加工具,选择Azure的AD的PowerShell。

    enter image description here

    +0

    它的工作原理现在? –

    +0

    这是行不通的..我能够运行powershell MSOL命令使用我的AAD控制台,但它的抛出错误,而我试图调试它使用visual studio(2015) – Aathira

    +0

    贾森叶 - 请让我知道是否有一些你可能知道的其他工作? – Aathira

    0

    到Azure ActiveDirectory连接页面的所有链接现在似乎无效。

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

    在提升PS会话

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

    运行这些当时我能够登录并运行OI需要什么

    相关问题