Share via


Office 365 Script to retrieve Verified Domains On Tenant

Office 365 Script to retrieve Verified Domains On Tenant

Introduction

This Wiki is based on Forum Post.

Requirement

Script to check is domain are Verified on Tenant or not.

Code Used
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
### Connect to Cloud ###

$O365Cred = Get-Credential
$O365Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session -allowclobber
Connect-MsolService -Credential $O365Cred

### Read CSV File ###

# $ReadCSV=(read-host -prompt "Enter Name of CSV :")
$DQdomain=import-csv -Path D:\LiveMigration\domain.csv    # "$ReadCSV"

# $DQdomain =get-content D:\LiveMigration\domain.csv

### Check if Verified in Tenant ###

foreach($domain in $DQdomain)
{
get-msoldomain -DomainName $domain.domain -status "unverified"
}
Summary

Explore the Command Get-MSOLDomain This command has two parameter sets so if we consume -DomainName indeed we can't use -Status.

Root Cause

Solution
001
Get-MsolDomain -Status Unverified
Alternative

OP has a scenario : Need to check only specified Domains from CSV file - So the Code is below

001
002
003
004
005
006
007
Import-Module MSOnline
$O365Cred = Get-Credential
$O365Session = New-PSSession â€“ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell `
-Credential $O365Cred -Authentication Basic -AllowRedirection
Import-PSSession $O365Session
Connect-MsolService â€“Credential $O365Cred
Import-Csv C:\Temp\Domain.csv | %{Get-MsolDomain -DomainName $_.Domain | ?{$_.Status -eq 'UnVerified'} |Select Name , Status}

Enjoy PowerShell :)