How to Fix SPMT Module ActiveX Single-threaded apartment Error

Kirsten 0 Reputation points
2024-09-24T14:31:44.2033333+00:00

I have created a Powershell tool to set up SharePoint sites and it uses the SharePoint Migration Tool. However, when trying to register an SPMT Migration, it fails with the following error:

Register-SPMTMigration : ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the 
current thread is not in a single-threaded apartment. 
At line:2 char:1 
+ Register-SPMTMigration -migratewithoutrootfolder -force -erroraction: ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo          : InvalidOperation: (:) [Register-SPMTMigration], AADAuthenticationException 
    + FullyQualifiedErrorId : MigrationLibError,Microsoft.SharePoint.MigrationTool.PowerShell.RegisterSPMTMigration

This occurs in PS7 and PS5, admin or normal user, and happens with just the following two commands:

Import-Module Microsoft.SharePoint.MigrationTool.PowerShell
Register-SPMTMigration -migratewithoutrootfolder -force -erroraction:stop

I've tried on multiple accounts and multiple versions of PowerShell. I've made sure everything is up to date. I've run the commands as the only script happening on my computer and the first commands run in a newly open PowerShell window. And, of course, I've restarted the computer.

I've also tried adding the following command prior to importing the module or registering the SPMT migration:

[Threading.Thread]::CurrentThread.SetApartmentState([Threading.ApartmentState]::STA)

Any help would be greatly appreciated.

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,972 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,510 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Emily Du-MSFT 46,166 Reputation points Microsoft Vendor
    2024-09-25T09:04:27.22+00:00

    Mare sure there is no windows update pending and connect to SharePoint Online first, then Register-SPMTMigration.

    $Global:UserName = "admin@contoso.onmicrosoft.com"
    $Global:PassWord = ConvertTo-SecureString -String "YourSPOPassword" -AsPlainText -Force
    $Global:SPOCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:UserName, $Global:PassWord
    
    Connect-SPOService -Url https://contoso-admin.sharepoint.com -Credential $Global:SPOCredential
    
    Import-Module Microsoft.SharePoint.MigrationTool.PowerShell
    Register-SPMTMigration -SPOCredential $Global:SPOCredential -Force
    

    If the issue exists, try to run PowerShell in another computer, compare the result.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.