Is it possible to use Azure Powershell to connect to Office 365

David Cordero 11 Reputation points
2022-06-01T19:24:50.377+00:00

I am trying to connect to Office 365 using Azure Cloud Shell or Powershell since we do not have windows systems. However after following these steps:

install-module AzureAD
install-module AzureADPreview
install-module MSOnline

Run Connect-MsolService and get
Connect-MsolService: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

Can I get some feedback?
Thanks

Azure Cloud Services
Azure Cloud Services
An Azure platform as a service offer that is used to deploy web and cloud applications.
767 questions
0 comments No comments
{count} vote

4 answers

Sort by: Most helpful
  1. risolis 8,741 Reputation points
    2022-06-02T20:40:45.7+00:00

    Hello @David Cordero

    Thank you for your post.

    I would like to give you my humble opinion on this as it is shown below:

    PS C:\Windows\system32> get-help connect* -detailed

    Name Category Module Synopsis


    Connect-PSSession Cmdlet Microsoft.PowerShell.Core Reconnects to disconnected sessions.
    Connect-WSMan Cmdlet Microsoft.WSMan.Manage... Connects to the WinRM service on a remote computer.
    Connect-AzAccount Cmdlet Az.Accounts Connect to Azure with an authenticated account for use with...
    Connect-AdbServer Function Adb ...
    Connect-AzureAD Cmdlet AzureAD Connect-AzureAD...
    Connect-MicrosoftTeams Cmdlet MicrosoftTeams Connect-MicrosoftTeams...
    Connect-AzContainerRegistry Cmdlet Az.ContainerRegistry Connect-AzContainerRegistry...
    Connect-AzureRmAccount Cmdlet AzureRM.profile Connect-AzureRmAccount...
    Connect-Workstation Function core ...
    Connect-Terraform Function Terraform ...
    Connect-IscsiTarget Function iSCSI ...
    Connect-VirtualDisk Function Storage ...

    ==========================================================================================================================================

    PS C:\Windows\system32> find-module -name MSonline*

    Version Name Repository Description


    1.1.183.66 MSOnline PSGallery Microsoft Azure Active Directory Module for Windows...
    1.0.51 MSOnlineExt PSGallery This PowerShell module was made to ease the burden ...
    0.1 MSOnlineLW PSGallery This is a lightweight version of the MSOnline modul...

    PS C:\Windows\system32>

    ==========================================================================================================================================

    PS C:\Windows\system32> Find-Package -name MSonline

    Name Version Source Summary


    MSOnline 1.1.183.66 PSNuGet Microsoft Azure Active Directory Module for Windows PowerShell
    MSOnline 1.1.183.66 PSGallery Microsoft Azure Active Directory Module for Windows PowerShell

    PS C:\Windows\system32>

    I hope this can be used for you.

    Cheers,

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


  2. risolis 8,741 Reputation points
    2022-06-04T08:13:24.397+00:00

    @David Cordero

    Are you getting this type of output?

    PS /home/ricardo> $credential = Get-Credential

    PowerShell credential request
    Enter your credentials.
    User: XXXXXx00@harsh.com .com
    Password for user XXXXXx00@harsh.com .com: ***********

    PS /home/ricardo>
    PS /home/ricardo> Connect-AzureAD -Credential $credential
    PS /home/ricardo>
    PS /home/ricardo> Connect-MsolService -Credential $credential
    Connect-MsolService: The term 'Connect-MsolService' is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    PS /home/ricardo>
    PS /home/ricardo>
    PS /home/ricardo> Connect-MsolService -Credential $cred -AzureEnvironment AzureCloud
    Connect-MsolService: The term 'Connect-MsolService' is not recognized as a name of a cmdlet, function, script file, or executable program.
    Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    PS /home/ricardo>

    PS /home/ricardo> find-Module -Name MSOnline

    Version Name Repository Description


    1.1.183.66 MSOnline PSGallery Microsoft Azure Active Directory Module for Windows PowerShell

    PS /home/ricardo>

    PS /home/ricardo> install-module -name MSonline -RequiredVersion 1.1.183.66 -Credential $credential -AllowClobber -force
    PS /home/ricardo>

    PS /home/ricardo>
    PS /home/ricardo> update-module -name MSonline -force
    PS /home/ricardo>

    PS /home/ricardo> import-module -name MSonline -force
    Import-Module: Assembly with same name is already loaded
    PS /home/ricardo>

    PS /home/ricardo> Get-InstalledModule MSonline

    Version Name Repository Description


    1.1.183.66 MSOnline PSGallery Microsoft Azure Active Directory Module for Windows PowerShell

    PS /home/ricardo>

    Cause I was trying to the same syntax running on the CLI terminal but I came across with one conclusion but please confirm if you are experiencing firstly.

    Cheers,


  3. risolis 8,741 Reputation points
    2022-06-04T19:15:40.013+00:00

    Hi David.

    I have to say that I was taking enough time to try to replicate the issue and trying to find out what the issue might be or what the solution would be so, I have concluded the following:

    Those links below are reporting the same behavior as the one you have describing previously:

    https://github.com/PowerShell/PowerShell/issues/7162

    https://stackoverflow.com/questions/71491341/microsoft-online-services-sign-in-assistant-download

    https://learn.microsoft.com/en-us/powershell/partnercenter/multi-factor-auth?view=partnercenterps-3.0#ms-online

    Also, It seems to be that the core file is missing and it is recommended to use AZURE AD module instead of MS online cmdlet.

    Check this below:

    PS /home/ricardo> Connect-MsolService -AzureEnvironment AzureCloud
    Connect-MsolService: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

    Connect-MsolService: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

    PS /home/ricardo> Get-Error

    Exception :
    Type : System.IO.FileNotFoundException
    Message : Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

    FileName   : System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089  
    TargetSite :   
        Name          : MsolCmdletProcessRecord  
        DeclaringType : Microsoft.Online.Administration.Automation.ConnectMsolService  
        MemberType    : Method  
        Module        : Microsoft.Online.Administration.Automation.PSModule.dll  
    Source     : Microsoft.Online.Administration.Automation.PSModule  
    HResult    : -2147024894  
    StackTrace :   
    

    at Microsoft.Online.Administration.Automation.ConnectMsolService.MsolCmdletProcessRecord()
    at Microsoft.Online.Administration.Automation.MsolCmdlet.ProcessRecord()
    at System.Management.Automation.Cmdlet.DoProcessRecord()
    at System.Management.Automation.CommandProcessor.ProcessRecord()
    TargetObject : Microsoft.Online.Administration.Automation.ConnectMsolService
    CategoryInfo : NotSpecified: (Microsoft.Online.Ad….ConnectMsolService:ConnectMsolService) [Connect-MsolService], FileNotFoundException
    FullyQualifiedErrorId : System.IO.FileNotFoundException: Could not load file or assembly 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The
    system cannot find the file specified.

                        File name: 'System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'  
                        at Microsoft.Online.Administration.Automation.ConnectMsolService.MsolCmdletProcessRecord()  
                        at Microsoft.Online.Administration.Automation.MsolCmdlet.ProcessRecord(),Microsoft.Online.Administration.Automation.ConnectMsolService  
    

    InvocationInfo :
    MyCommand : Connect-MsolService
    ScriptLineNumber : 1
    OffsetInLine : 1
    HistoryId : 56
    Line : Connect-MsolService -AzureEnvironment AzureCloud
    PositionMessage : At line:1 char:1
    + Connect-MsolService -AzureEnvironment AzureCloud
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName : Connect-MsolService
    CommandOrigin : Internal
    ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo :


  4. risolis 8,741 Reputation points
    2022-06-07T17:45:22.307+00:00

    Hello @David Cordero

    I hope you are doing fine,

    I just wanted to know if further assistance is required at this moment. Besides that, I would like to share the next output below:

    209205-image.png

    Looking forward to your feedback,

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.