Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

Connect-MsolService error after importing MSOnline module

$
0
0

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.


Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>