Exchange Corner
Let’s assume that you work for a company that has Exchange 2016 and has big amount of databases (50-100 DB).
You constantly delete databases to clear white space or for whatever reason but don’t usually keep on deleting folders or lost track of which database is deleted in your DB Folder.
In the following PowerShell script I am going to demonstrate how to check which of the folders in my D drive (Database drive) has an existing Database and which do not have.
The below script gets all folders in the drive path D:\Databases to check if they exist or not.
# Get deleted database that still has remaining non deleted folders
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
$databases = Get-ChildItem D:\Databases\* -Directory | select Name
foreach ($database in $databases)
{
$DB = $database.Name
if ((Get-MailboxDatabase -Identity $db -ErrorAction Ignore ))
{
write-host "Database $($db) exists on Exchange Server" -ForegroundColor Green
}
else
{
Write-Host "Database $($db) doesn't exist on Exchange Server " -ForegroundColor Red
}
}
I did not add the part to delete the folder through the script as it is still a risky thing to automate and would rather do the deletion manually after double confirming it’s totally gone.
For more about Exchange Server related articles please visit Exchange section here
Hope this helps.
Reset and manage your Active Directory users' Passwords Active Directory is one of the most…
Finding Exchange Database hidden mailboxes. Story:Maybe you have been in this situation before, trying to…
If you're using a Proxy server in your firewall or in your network and have…
Story:I got some clients that have reported some of their users being locked out and…
Delegate Permissions This is a code that I have wrote recently to check if an…
Story: I got a request from a client who constantly gets CVs and have to…