Category Archives: Dirsync

Connect-MsolService fails with Exception of type was thrown

If you are working on Windows 10 and try to connect to Microsoft Online PowerShell you might get exposed to couple of failures and errors.

The first error that would appear is the following:


Connect-msolservice : Exception of type ‘Microsoft.Online.Administration.Automation.MicrosoftOnlineException’ was
thrown PS C:\WINDOWS\system32> $msolcred = get-credential

Cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
PS C:\WINDOWS\system32> connect-msolservice -credential $msolcred
connect-msolservice : Exception of type ‘Microsoft.Online.Administration.Automation.MicrosoftOnlineException’ was
At line:1 char:1
+ connect-msolservice -credential $msolcred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : OperationStopped: (:) [Connect-MsolService], MicrosoftOnlineException
     + FullyQualifiedErrorId : 0x800434D4,Microsoft.Online.Administration.Automation.ConnectMsolService

The first thing that came to mind was the MFA that Microsoft has forced during this month. So I created an app password and tried it but that didn’t work neither and I got the following error


PS C:\WINDOWS\system32> $msolcred = get-credential

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
PS C:\WINDOWS\system32> connect-msolservice -credential $msolcred
connect-msolservice : The user name or password is incorrect. Verify your user name, and then type your password again.
At line:1 char:1
+ connect-msolservice -credential $msolcred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : OperationStopped: (:) [Connect-MsolService], MicrosoftOnlineException
     + FullyQualifiedErrorId : 0x80048821,Microsoft.Online.Administration.Automation.ConnectMsolService

I checked the following links on google to see if I am up to date

Apparently the only thing not mentioned is how to update the MSOnline module on your computer, Microsoft requires Latest module of MSOnline 1.1 in order for you to connect.

Get-Module MSOnline


Solution 1:

In order for you to get this to work, You need to update the module manually using Powershell with Administrative Privileges.

First Find the module and make sure it reads the latest version which is supposed to be different than the one installed on your PC.

Find-Module -name MSOnline


Trying to Install MSOnline using the following CMDLet resulted in a warning that I am using version 1.0 and need to use –force parameter.

Install-Module -Name MSOnline


Solution 2:

Instead, I used the following cmdlet to force installation of version but also ended up with an error stating the following:

Find-Module -name msonline |Install-Module –Force


PackageManagement\Install-Package : The following commands are already available on this system:’Add-MsolAdministrative

Solution 3:

The parameter which resolves the issue is the –AllowClobber, AllowClobber Overrides warning messages about conflicts with existing commands. Overwrites existing commands that have the same name as commands being installed according to MS’s article.

Find-Module -name msonline |Install-Module -Force –AllowClobber

You should now close Powershell and relaunch it as administrator and the moment you type Connect-MsolService you should get a window asking for your credentials.




Symptoms: You may notice that when you try to run the Sync command DirectorySyncClientCmd it doesn’t do anything and just closes right away.

If you open your Event viewer you may notice that you are getting the following event


Failed while Purging Run History
Invalid namespace
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at Microsoft.Azure.ActiveDirectory.Synchronization.DirectorySyncClientCmd.Program.PurgeRunHistory(TimeSpan purgeInterval)
at Microsoft.Azure.ActiveDirectory.Synchronization.Framework.ActionExecutor.Execute(Action action, String description)
at Microsoft.Azure.ActiveDirectory.Synchronization.DirectorySyncClientCmd.Program.Main(String[] args)


This happens when the WMI object had unregistered itself which might be caused by another tool installed or uninstalled at the time when the problem started to occur.


To resolve the issue, you ‘ll have to run few command lines… each are explained below

mofcomp “D:\Program Files\Microsoft Azure AD Sync\Bin\mmswmi.mof”

As it shows in the command screenshot below the ‘mofcomp’ parses the MMS (FIM) wmi file and goes through the process of adding the classes  to the WMI repository.


regsvr32 /s “D:\Program Files\Microsoft Azure AD Sync\Bin\mmswmi.dll”

Registers the WMI mmswmi.dll file to the server.


net stop winmgmt /y


net start winmgmt
net start “IP Helper”
net start “User Access Logging Service”
net start “Microsoft Azure AD Sync”


D:\Program Files\Microsoft Azure AD Sync\Bin\DirectorySyncClientCmd.exe”







Installing and configuring Azure Active Directory Sync and use IDFIX

To install Azure Active Directory Sync , we will have to prepare prerequisites

To prepare Azure Active Directory Sync Server, you will need to download the following tools to check for users attributes on your local AD:

  1. Mirosoft Windows Server 2008R2/2012R2
  2. NetFramework 4 (For IDFIX tool to work)
  3. IDFIX (to Check if there’s any issue on AD with DirSync)


One of the new features that came with AADSync is that it can be installed on the DC server as well. but some may choose to have it on a separate server to avoid any risk.


Software Prerequisites

Install required tools for Azure Active Directory Connector (Dirsync)

  1. AADSYNC latest version (Download here) (Version Review link)
  2. Microsoft Online Services Sign-In Assistant for IT Professionals RTW (Here)
  3. Azure Active Directory Module for Windows PowerShell (64-bit version) (Here)



Additionally, to connect and synchronize to Office 365, the following prerequisites need to be installed before installing AADSYNC…

Install “Windows Azure Active Directory Module for Windows PowerShell (64-bit version)”.  It is highly recommended that this machine be restarted before installing DirSync.


NOTE: Effective October 20, 2014, the 32-bit version of Azure Active Directory Module for Windows PowerShell is discontinued. Support for the 32-bit version will no longer occur, and future updates to the Azure Active Directory Module will be released only for the 64-bit version. We strongly recommend you install the 64-bit version to ensure future support and compatibility. Refer to “Install the Azure AD Module” in Manage Azure AD using Windows PowerShell.


If DirSync is to be installed on a server with Windows 2008 R2, beginning with version 1.0.6765.0006, PowerShell 3.0 is required and can be installed from Windows Management Framework 3.0; AND beginning with version 1.0.6985.000, .NET Framework 4.5.1 is a prerequisite.


From <>


Installing Netframework 4.5




Once you download IDFIX, you have to unzip and run the exe tool

Right click on Idfix and run it as administrator to give it the required privileges to access AD users and groups.



After you run it, it must look like the following



After running the tool you will have to click on Query to get the problematic users/groups and solve the ones that you want them to be synced to Office 365 Azure AD.

Top Level Domain:

The most common issue that occurs when preparing for AADSYNC is the Top Level domain users related errors (If .local is used)


To Fix this issue for all the users/groups which will be synced to O365 you will have to open Active Directory Domains and Trusts:

Right click on Active directory domains and trusts and click properties then add your public domain to the Alternative UPN Suffixes:




Next open Active directory users and computers to change the UPN to the correct one that matches your public domain.


Changing the domain suffix for your users suffixes won’t affect their login to their machines or any other application server.




Select the users in which OU that you want it to be synced and right click and choose Properties.







Proxy Address:

You might as well face another issue with users that you intend to sync to Office 365 which is the SMTP proxy address. in some Exchange Organizations the e-mail policy might be set wrong and therefore the user might have an invalid domain value in his proxyaddress attribute e.g. user@domain.local


To solve this, there are 3 ways to solve it. First would be to use Exchange on-premises Email policy to delete the .local SMTP proxy and set the public domain one.

The other two ways would be that you delete the proxyaddress manually or with a powershell script . I personally prefer to do this manually due to avoid any risk that it may impose on the users objects.

Another method would be the IDFIX it self or Admodify.

In the below snapshot I used IDFIX to fix the proxyaddress of the problematic users.



Installation of ADDSYNC 

First we’ll install Microsoft Online Services Sign-In Assistant for IT Professionals RTW…


Next Windows Azure AD powershell module


Installing AADirsync






In the next step you will have to enter an Office 365 Global administrator user (preferably not user) and I would recommend that you create a cloud user on Office 365 with global admin privileges to use with AADSYNC.


Next before you continue, you should open your O365 portal and Enable ADSync there.


When you click on Set up the following page should come to you. you should click on Activate AD Sync.




Now you may continue to config AADSYNC, below I am going to use a different user that’s dedicated only to “AADSYNC” tool. I will calll it




Next On Active directory on-premises I will configure a new user called (Dirsync) that’s member of enterprise admins. this user will have access to all the OUs that will be synced in order to sync their attributes and passwords..etc



Once you enter your Enterprise domain account below and click add forest, it will be enlisted below and you can add additional number of forests if you have more.





Next you may choose to have Hybrid deployment if you have Exchange on-premises (At least Exchange 2010 SP3) but if not then no need to tick the box. The password write-back is a feature that requires an Azure premium AD subscription so if you don’t have this subscription then you don’t really need to tick this box.


The Azure AD app and attribute filtering is a feature that allows you to pick a certain application attribute you want to sync back and forth to Azure AD e.g. (Exchange, SharePoint..etc). If you don’t tick this box the normal standard attributes will be synced which will include (Exchange and user’s basic info) you can find it as soon as the setup finished and you open ADDSync UI.



Password writeback overview

Password writeback is an Azure Active Directory Sync component that can be enabled and used by the current subscribers of Azure Active Directory Premium. For more information, see Azure Active Directory Editions. It allows you to configure your cloud tenant to write passwords back to you on-premises Active Directory. It obviates you from having to set up and manage a complicated on-premises self-service password reset solution, and it provides a convenient cloud-based way for your users to reset their on-premises passwords wherever they are. Read on for some of the key features of password writeback:

From <>

You can enable filtering in AADSync at any time. If you have already run the default configurations of directory synchronization and then configured the filtering, the objects that are filtered out are no longer synchronized to Azure AD. As a result, any objects in Azure AD that were previously synchronized but were then filtered are deleted in Azure AD. If objects were inadvertently deleted because of a filtering error, you can re-create the objects in Azure AD by removing your filtering configurations, and then synchronize your directories again.

From <>



Next I will not tick Synchronize now because this will sync All local AD objects and OUs to the cloud, in my case I just want to choose particular OUs to sync to the cloud.




In order to configure AADSYNC to choose which on-premises Active directory Organization Unit you want to change you will have to navigate to the following path on the server which you installed AADSYNC.


C:Program FilesMicrosoft Azure AD SyncUIShellmiisclient.exe

Right click on domain.local and click properties


Next Click on “Configure Directory Partitions” and Under “Credentials” Click on Containers and enter your new on-premises enterprise admin account.



Next select the OU you want to sync to the cloud and click OK



Next you will want to open “Task Scheduler” on the server and Enable the task that was created by AADSYNC installation to enable every 3 hours sync..



In order to Force the sync you will have to run a separate command that Microsoft has brought along with AADSYNC called “DirectorySyncClientCmd” the command can be run from Powershell or made a shortcut on a desktop and directly run.


c:Program FilesMicrosoft Azure AD SyncBinDirectorySyncClientCmd


Hope you find this useful. Winking smile 

Copy Immutable ID and Proxy Addresses from Azure to AD

Reuse DirSync in a new server after removing DirSync or in case DirSync server has crashed or no longer working.

In order to do so you will have to launch Azure powershell in admin mode and connect to MSOL service as in the following snapshot

$cred = get-credential
After connecting then type/copy the following
Get-MsolUser -ReturnDeletedUsers -All | Out-GridView


Once you type enter a GUI will come up showing you all the deleted users list, you should delete any old non-usable account that has similar attributes to the ones that you’re about to Sync from the AD to O365.


Once you’re sure about what do you want to delete you can go ahead with the following Command to delete the users

You must be sure that when you run this command, you will no longer be able to restore any deleted item or object later on.

Get-MsolUser -ReturnDeletedUsers -All | Remove-MsolUser -RemoveFromRecycleBin -Force –Verbose


Now you should run the following Script on the same open powershell in order to start the copying process.

Import-Module Msonline
Import-Module ActiveDirectory
$cred = Get-Credential
Connect-MsolService -Credential $cred
$onlineusers = Get-MsolUser -All
$adusers = Get-ADUser -Filter *

Press enter and when you want you get prompted to select an option choose 1 and enter


After the copy is finished you can match for yourself the list of ImmutableID along with the GUID
Ldifde -f dump.txt




Hope you find this useful coz I did Winking smile