Terug naar hoofdinhoud

Here are some handy commands for Exchange 2010.

 

- How to remove users from Exchange without removing them from AD

First get Disabled users :

Get-MailboxDatabase | Clean-MailboxDatabase

 

$mailboxes = Get-ExchangeServer | Where-Object {$_.IsMailboxServer –eq $true} | ForEach-Object { Get-MailboxStatistics –Server $_.Name | Where-Object {$_.DisconnectDate –notlike ‘’}} | select displayname, mailboxguid, database

 

Remove Disabled users :

 

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

 

You will recive the following error when there are no disconnected mailboxen in the disconnected mailbox folder, you can then ignore the message

 

Cannot bind argument to parameter 'Database' because it is null.
+ CategoryInfo : InvalidData: (:) [Remove-Mailbox], ParameterBindingValidationE
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Remove-Mailbox

 


Change Languages for the user(s)

When yo want to change a Language for a user enter the following :

 

Set-Mailbox -Identity "Full Username - John Smith" -Languages "uk-UK / jp-JP / nl-NL etc."

 

If you want all the users changed :

 

$servers = Get-mailboxserver | where {$_.admindisplayversion -like "Version 14*"}
foreach($server in $servers)
{Get-Mailbox -server $server -resultsize unlimited | SET-mailbox -languages "uk-UK / jp-JP / nl-NL etc"}

 

Go in the users mailbox using the web interface and set in OPTIONS --> ALL OPTIONS --> SETTINGS --> Country Settings the language.

do not forget to select the change all default maps !

 

Get Statistics of all active (not disconnected) mailboxes

Run the following command to get the Total item size & Item count:

 

Get-MailboxStatistics -server servername| ?{$_.totalItemSize.Value.ToMB() -gt 500} | Sort-Object TotalItemSize -Descending | Select DisplayName,@{name="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | Export-CSV c:\stats.csv -force -noTypeInformation -encoding ASCII

* Set the Servername & file location + filename of the cvs !

 

Add access privileges

 New-ManagementRoleAssignment -Name:"MailStore Impersonation" -Role:ApplicationImpersonation -User:Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken.

Important notice: Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken. is the user account in UPN (User Principal Name) notation which you will use to access the mailboxes from MailStore. Please make sure that this user is not a member of any Exchange or Windows administrative group.

Check access privileges

 Get-ManagementRoleAssignment -Role:ApplicationImpersonation -RoleAssigneeType:User | Format-List *

 Get-ManagementRoleAssignment -Identity:"MailStore Impersonation" | Format-List *


Remove access privileges

The following command is only to be used, if you want to remove access privileges from Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken.

Remove-ManagementRoleAssignment "MailStore Impersonation"

Creating and Assigning an Individual Throttling Policy

To avoid interfering with the overall stability of the Exchange 2010 system by using a too liberal policy definition of the default throttling policy, it is advisable to create a separate policy for the serviceaccount. Only three lines are necessary to create a throttling policy for the serviceaccount which is customized for MailStore:

 New-ThrottlingPolicy MailStore 
 
 Get-ThrottlingPolicy MailStore | Set-ThrottlingPolicy -EWSFindCountLimit 2500 -EWSPercentTimeInAD 70 -EWSPercentTimeInCAS 120 -EWSPercentTimeInMailboxRPC 80
 
 Set-Mailbox "servcieaccount" -ThrottlingPolicy MailStore

In line 1, a new throttling policy is created, line 2 defines the desired values for the policy, and in line 3, the individual throttling policy is assigned to the serviceaccount.

Important: Please note that a mailbox must be set up for the serviceaccount in order to be able to assign a policy to it.

Removing and Deleting an Individual Throttling Policy

To delete an individual throttling policy from a mailbox or user account, execute the following command in the Exchange Management Shell:

 Set-Mailbox "Serviceaccount" -ThrottlingPolicy $null

This ends the assignment of a throttling policy. To delete the throttling policy from the Exchange system, execute the following command in the Exchange Management Shell:

 Remove-ThrottlingPolicy MailStore 

Confirm this by entering "Y". The policy is now completely deleted from the system.

 

Handy commands

 

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 Dit e-mailadres wordt beveiligd tegen spambots. JavaScript dient ingeschakeld te zijn om het te bekijken.

“{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}}