Skip to main content

Remove Domain From Microsoft 365 Account By Using Powershell Command

Most of the IT person, would have face an issue with domain removal from the Microsoft tenant account. As, if you wish to remove the domain which you don't want in Microsoft 365. Generally while removing the domain, its giving an error the domain removal is in progress but as per most of the scenarios the domain removal may take lots of time, to save your precious time this blogs is designed to help you that how you can save your time by using Powershell command.

In this blog will walk you through how you can remove the domain by using Powershell command.


Steps1: Open the Powershell from by clicking on Windows+X key

Steps2: Click on Windows Powershell (Admin)

Steps3: Type the below command 

        

Command 1 ) Set-ExecutionPolicy RemoteSigned


Once you type the above command the below Page will appear, at the end of the Colon you need to type A


( Execution Policy Change The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at

https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy? [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A )


Command 2)  $UserCredential=Get-Credential


After entering the above command it will ask to connect the Powershell to Microsoft 365, type your Microsoft credential in the asking field.


Command 3) $s=New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell/ -credential $UserCredential -Authentication Basic -AllowRedirection


( WARNING: Your connection has been redirected to the following URI: "https://outlook.office365.com/PowerShell-LiveID?PSVersion=5.1.19631.1"

WARNING: Using New-PSSession with Basic Authentication is going to be deprecated soon, checkout https://aka.ms/exops-docs for using Exchange Online V2 Module which uses Modern Authentication. )


Command 4) import-PSSession -session $s

( WARNING: The names of some imported commands from the module 'tmp_w3hyb5ee.uzp' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.)


ModuleType Version    Name                                ExportedCommands

----------          -------    ----                                        ----------------

Script     1.0        tmp_w3hyb5ee.uzp                    {Add-AvailabilityAddressSpace, Add-DistributionGroupMember, Add-MailboxFolderPermission, Add-MailboxLocation...}


Command 5) Install-Module MSOnline


( Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A )


Command 6)  Connect-MsolService


Command 7)  Get-MsolDomain


Name                       Status   Authentication

----                           ------    --------------

surajb.onmicrosoft.com Verified Managed

surajb.com             Verified Managed


Command 8) Remove-MsolDomain -DomainName surajb.com


( Note: While typing the domain name in Powershell make sure that, you should have replaced the surajb.com domain to your actual domain name. )


Confirm Continue with this operation?

[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): Y


Once you confirm Yes, then the domain will be removed automatically from your Microsoft 365 tenant.


๐Ÿ˜Š๐Ÿ˜ƒThank you for reading the blog, please do like, share & share your thoughts in comment section.

Comments