locked
Connect-MsolService error after importing MSOnline module RRS feed

  • Question

  • I'm receive the following error when I run Connect-MsolService -

    Exception of type 'Microsoft.Online.Administration.Automation.MicrosoftOnlineException' was thrown. + CategoryInfo : OperationStopped: (:) [Connect-MsolService], MicrosoftOnlineException + FullyQualifiedErrorId : 0x80090345,Microsoft.Online.Administration.Automation.ConnectMsolService + PSComputerName : xxxxx

    Background - I am using powershell to manage Active Directory, Exchange and Sharepoint Online user data. I have an SSIS package that dynamically builds arguments passed to powershell scripts for creating new and updating existing AD user data, adding/updating necessary security and distribution groups for each user, enabling exchange mailboxes, and passing custom attribute data to Sharepoint online user profiles.

    In effort to maintain the purity of the SQL server running the SSIS package, dynamic sessions are created to servers having the modules necessary for import. This allows me to do all of the things mentioned above without having to install the different modules on my SQL server.

    My final hurdle is automating the Office 365 licensing. To script licensing assignments I create a session to our server having the necessary MSOnline module and import it giving me access to the Cmdlets, like Set-MsolUserLicense. However, before I can use the Cmdlets I have to connect to the MSOLService.

    When I run Connect-MsolService, the credentials modal pops as expected, the appropriate credentials are entered (which have been verified a thousand times over), and I receive the error shown above.

    These commands all work fine when I run them from the server where the MSOnline cmdlets are installed, but return the error when run post successful import-module on my SQL server.

    Here are the commands used for establishing the session and importing the MSOnline module -

    $securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
    $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $securePassword
    
    $outputSession = $Null
    foreach($session in Get-PSSession){
        if(($session.ComputerName -eq $Server) -and ($session.Availability -eq "Available")){
            $outputSession = $session
        }
    }
    if ($outputSession -eq $Null){
        $outputSession = New-PSSession -ComputerName $Server -Credential $cred -Name 'MSOnline'
        Invoke-Command -Session $outputSession -ScriptBlock {Import-Module MSOnline}
        Import-PSSession -session $outputSession -module MSOnline -AllowClobber
    }
    

    Connect-MSOLService is the only Cmdlet giving me an issue using these methods. Any help you can provide will be appreciated.

    Monday, July 21, 2014 3:06 PM

Answers

  • Hi,

    I suspect its a problem with authentication in Power Shell.
    Would you be able to install Sign In Assistant and check if that works for you?

    Please refer the following link for assistance with the installation:

    http://technet.microsoft.com/en-us/library/jj151815.aspx#BKMK_Requirements

    Regards,
    Malar.

    Tuesday, July 22, 2014 3:08 PM

All replies

  • Hi,

    I suspect its a problem with authentication in Power Shell.
    Would you be able to install Sign In Assistant and check if that works for you?

    Please refer the following link for assistance with the installation:

    http://technet.microsoft.com/en-us/library/jj151815.aspx#BKMK_Requirements

    Regards,
    Malar.

    Tuesday, July 22, 2014 3:08 PM
  • Thanks, Malar.  We'd hope to accomplish the connection without having to install anything locally.  However, after much trial and error and discussion with Microsoft support team we settled on that the components must be installed locally to work.  

    So, we finally gave up attempting to use the tools from a remote server, installed the MSOL sign-in assistant and the Azure Active Directory module for Powershell locally and were able to complete the connection.

    Rocky


    Thursday, July 24, 2014 6:03 PM
  • Hi Rocky,

    Regret the inconvenience caused and I'm glad that its working now.

    Regards,
    Malar.

    Friday, July 25, 2014 8:22 AM
  • I know this is an old thread.

    But I seem to be having the exact same issue and tried to follow the steps taken to resolve this as mentioned in this thread. Still no success.

    can you help?

    Monday, March 9, 2015 7:33 PM