Exchange 2010 Usefull Powershell Commando’s

This entry was posted by on Thursday, 8 April, 2010 at

Exchange PowerShell
 

 

Usefull Exchange 2010 Powershell Commando’s   

{Get mailbox copy status information}

Get-MailboxDatabaseCopyStatus -Identity “Mailbox Database Name” | select DatabaseName,Status,ActiveDatabaseCopy,ContentIndexState

“{Import PST Files}”
Get-Mailbox -Database “Mailbox Database Name”| Import-Mailbox -PSTFolderPath “Path import pst file location”

“{Get Information about a mailbox}”
Get-MailboxStatistics

“{Purge Disconnected Mailbox}”
Get-MailboxStatistics -database “Mailbox Database Name” | where {$_.disconnectdate -ne $null} | foreach {Remove-mailbox -database $_.database -storemailboxidentity $_.mailboxguid}

or

$users = Get-MailboxStatistics -database “Mailbox Database Name” | where-object { $_.DisconnectDate -ne $null } | Select DisplayName,MailboxGuid,Database

$users | ForEach { Remove-Mailbox -Database $_.Database -StoreMailboxIdentity $_.MailboxGuid -confirm:$false }

“{Run cleanup agent}”
Clean-MailboxDatabase -Identity “Mailbox Database Name”

“{Show all Mailboxes which are bigger than 400 mb and sorted}”
Get-MailboxStatistics -server “Mailbox Server Name”| Where-object {$_.TotalItemSize -gt 400mb} | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label=”TotalItemSize (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},ItemCount > “Outputfile”.txt

“{Show mailbox Size From a user in MB}”
Get-MailboxStatistics “Samaccountname” | ft DisplayName, TotalItemSize, ItemCount

“{Whitelist a sender}”
Set-ContentFilterConfig -BypassedSenders “mail_address@microsoft.com”

“{Show mailbox databases storage quota}”
Get-MailboxDatabase | select Identity,IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota

“{Set ‘send-as’ Rights}”
Add-ADPermission -Identity “mailbox user” -User “Useraccount” -ExtendedRights ‘Send-as’

“{Set ‘Full Access’ Rights}”
Add-ADPermission -Identity “mailbox user” -User “Useraccount” -AccessRights ‘FullAccess’

“{Get Mailbox users which never logged-on}”
Get-MailboxStatistics -server “Mailbox Server Name” | Where-object {$_.LastLogonTime -lt 1}

“{Mailbox users who logged on after  3-31-2010}”
Get-MailboxStatistics -server “Mailbox Server Name”| Where-object {$_.LastLogonTime -gt “3/31/2010”}

“{Show mailbox forwarding roles}”
Get-InboxRule -mailbox “Mailbox Account” | fl MailboxOwnerId,enabled,RedirectTo,Description

“{Add Database copy to a Mailbox server }”
Add-MailboxDatabaseCopy -Identity ‘Database Name’ -MailboxServer ‘Mailbox Server Name’ -ActivationPreference ‘5’

“{Update Database Copy (Reseeding), Delete files if exist}”
Update-MailboxDatabaseCopy -Identity “DB1\MBX1” -DeleteExistingFiles -Network $null

“{Reseed the Search Catalog}”
Update-MailboxDatabaseCopy -Identity “DB1\MBX1” -CatalogOnly

“{Certificate Generate CSR}”

New-ExchangeCertificate -FriendlyName ‘Test’ -GenerateRequest -PrivateKeyExportable $true -KeySize ‘2048’ -SubjectName ‘C=NL,S=”Noord-Brabant”,L=”Eindhoven”,O=”more2know”,OU=”ICT”,CN=webmail.more2know.nl’ -DomainName ‘autodiscover.more2know.nl’

“{Import Certificate}”
Import-ExchangeCertificate -FileData ([Byte[]]$(Get-Content -Path c:\certificates\ExportedCert.pfx -Encoding byte -ReadCount 0)) -Password:(Get-Credential).password

In the popup enter a username. It will not used. Enter the password that protect your pfx certificate

“{Show free Space Database}”

Get-MailboxDatabase -Status | Select-Object Server,Name,AvailableNewMailboxSpace

“{Create a new Recovery Database}”
New-MailboxDatabase -Recovery -Name “A name for the recovery Database” -Server “Mailbox Server” -EdbFilePath “path edb file” -LogFolderPath “Log folder path”

“{Recover A Mailbox from the Recovery Database}”
Restore-Mailbox -Identity “Sammaccount name” -RecoveryDatabase “Name of the Recovery Database”

“{Recover A Mailbox from the Recovery Database to folder}”
Restore-Mailbox -Identity “Sam Account Name where to restore” -RecoveryDatabase “Name Recovery Database” -RecoveryMailbox “Sam Account Name recovery mailbox” -TargetFolder “A Folder Name”

“{Recover A Mailbox Content from the Recovery Database to folder}”
Restore-Mailbox -Identity “Sam Account Name where to restore” -RecoveryDatabase “Name Recovery Database” -RecoveryMailbox Sam Account Name Recovery Mailbox” -SubjectKeywords “text” –ContentKeywords “text” –IncludeFolders \inbox,\calendar –TargetFolder “a Folder Name”

“{Restore all from Recoverydatabase}”
Get-Mailbox -Database “Database Name” | Restore-Mailbox -RecoveryDatabase “Recovery Database Name”

“{Remove Recoverydatabase}”
Remove-MailboxDatabase -Identity “Name recovery Database”

“{Suspent all databases on a server for activation only}”
Get-MailboxDatabaseCopyStatus –Server (hostname) | Suspend-MailboxDatabaseCopy –ActivationOnly –Confirm:$false

“{Resume all databases after a suspend only activation only}”
Get-MailboxDatabaseCopyStatus –Server (hostname) | Resume-MailboxDatabaseCopy 

“{Move all database to another server}”
 Move-ActiveMailboxDatabase -Server (hostname) -ActivateOnServer Ex2

“{Show all activation preferences}”
Get-MailboxDatabase | Select Name, ActivationPreference, Server

“{Mount database on the server with preference 1 (with colors)}”
Get-MailboxDatabase | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference| Where {$_.Value -eq 1};  Write-Host $db “on” $xNow “Should be on” $dbOwn.Key -NoNewLine; If ( $xNow -ne $dbOwn.Key){Write-host ” WRONG” -ForegroundColor Red; Move-ActiveMailboxDatabase $db -ActivateOnServer $dbOwn.Key -confirm:$False} Else {Write-Host ” OK” -ForegroundColor Green}}

“{Verify if the database is mounted on the server with preference 1 (with colors)}”
Get-MailboxDatabase | Sort Name | ForEach {$db=$_.Name; $xNow=$_.Server.Name ;$dbown=$_.ActivationPreference| Where {$_.Value -eq 1};  Write-Host $db “on” $xNow “Should be on” $dbOwn.Key -NoNewLine; If ( $xNow -ne $dbOwn.Key){Write-host ” WRONG” -ForegroundColor Red; } Else {Write-Host ” OK” -ForegroundColor Green}}


Leave a Reply

You must be logged in to post a comment.