Exchange 2007 Powershell commands

26 Aug 2010 by Simon Greaves

Receive Connector

Define the FQDN:
Set-ReceiveConnector <Connector-Name> –Fqdn:[name.company.ca] (http://name.company.ca)
Set up Anonymous Authentication:
(take a note of the current groups)
Get-ReceiveConnector <Connector-Name> | Select PermissionsGroups

(use the current value plus the new value)
Set-ReceiveConnector <Connector-Name> –PermissionGroups:<AnonymousUsers, ExchangeUsers, ExchangeServers, ExchangeLegacyServers, Partners>

ADMINISTRATION

New Mailbox User:
New-Mailbox -Name <name> -Alias <alias> -Database <mailboxdatabasename> -UserPrincipalName <alias>@<domain.local> -OrganizationalUnit <domain.local>/OU/OU -Password <password>

Move all users from one server to another:
Get-Mailbox -Server SRV1 | Move-Mailbox -TargetDatabase SRV2

INFO

Exchange Organization Name:
Get-OrganizationConfig | select name

STATISTICS

Mailbox Sizes in MB:
Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{expression={$_.TotalItemSize.Value.ToMB()}},ItemCount

Find account with SMTP address:
Get-Mailbox | where {$_.emailAddress -contains <emailaddress@domain.com>} | select name

Get-Recipient -identity <emailaddress@domain.com>

Current connections to Exchange Server:
get-logonstatistics -server <servername> | select username,clientversion

Count of mailboxes per database:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object -property:database | Sort-Object -property:count | Format-Table count, name -AutoSize

Count of mailboxes per server:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object -property:serverName | Sort-Object -property:count | Format-Table count, name -AutoSize

Count of mailboxes in entire Exchange Org:
Get-MailboxDatabase | Get-MailboxStatistics | Group-Object

count of mailboxes grouped by Email Address Policy enabled/ disabled:
Get-Mailbox | Group-Object -property:emailaddresspolicyenabled | Sort-Object -property:count | Format-Table count, name -Autosize

CERTIFICATES

Generate Certificate Request:
New-ExchangeCertificate -GenerateRequest -Path <pathforcsrfilecertname.csr> -KeySize 1024 -SubjectName "c=GB, s=<County>, l=<town>, o=<companyname>, cn=<commoncertname/externalfqdn>" -DomainName <autodiscover.domain.com>, servernetbiosname, serverfqdn> -PrivateKeyExportable $True

Import Certificate:
Import-ExchangeCertificate –Path <drive:pathcertfilename.cer>

Find Thumbprint for Imported Certificate:
Dir cert:LocalMachineMy | fl

Bind Certificate to Exchange Services:
Enable-ExchangeCertificate -Thumbprint <thumbprint> –Services "SMTP,IIS"

Get Certificate Status:
Get-ExchangeCertificate

Export Certificate:
$password = Read-Host "Enter Password" -AsSecureString Export-ExchangeCertificate -Thumbprint <certthumbprint> -Password $password -Path <pathtoexportcert.pfx>

Import PFX Certificate with Public Key:
Import-ExchangeCertificate -Path c:certificatesimport.pfx -Password:(Get-Credential).password
[Anything can be entered in username, enter public key in password]

SCR (Standby Continuous Replication)

Enable SCR on Storage Group:
enable-storagegroupcopy -identity <storagegroupGUID> -standbymachine exch1b -ReplayLagTime 0.1:0:0

Disable SCR on Storage Group:
disable-storagegroupcopy -identity <storagegroupGUID> -standbymachine exch1b

Get SCR Status of Storage Group:
get-storagegroupcopystatus -identity <storagegroupGUID> -standbymachine exch1b

CCR/LCR

Suspend replication:
suspend-storagegroupcopy -identity <clusternamestoragegroupname>

Resume replication:
Resume-storagegroupcopy -identity <clusternamestoragegroupname>

Reseed passive node:
suspend-storagegroupcopy -identity <clusternamestoragegroupname>

Remove all database, transaction log and checkpoint files from passive node
Update-StorageGroupCopy <clusternamestoragegroupname>
Get-Storage GroupCopyStatus (to check replication after copy resumed)

CLUSTER

Which node is the active/ passive node:
Get-ClusteredMailboxServerStatus -Identity <ClusteredMailboxServerName>

ClusteredStorageType for all Mailbox Servers (Shared-SCC, Non-Shared-CCR, None-Mailbox)
Get-MailboxServer

Manually Switch Active Node:
Move-ClusteredMailboxServer -Identity:<ClusteredMailboxServerName> -TargetMachine:<NodeName> -MoveComment:<comment>

NLB/ CAS/ HUB

Check which users logged onto which CAS server:
Get-LogonStatistics -Server <CASServerName>

Enable Outlook Anywhere:
Enable-OutlookAnywhere -Server <CASServerName> -SSLOffloading:$false -ExternalHostname <externalFQDN> -ClientAuthenticationMethod basic -IISAuthenticationMethods basic

ADMINISTRATION

Specify -Password option as secure string:
$password = Read-Host "Enter password" -AsSecureString

Create New Mailbox:
New-Mailbox -Name "<name>" -Database "<First Storage GroupMailbox Database>" -OrganizationalUnit domain.local/OU/OU -Alias <alias> -UserPricipalName <user>@<domain.local> -FirstName Chris -LastName Ashton -DisplayName "Chris Ashton" -Password $password

STATISTICS/ INFO

Check if mailbox still in dumpster (mailbox retention period expired):
Get-MailboxStatistics | where { $_.DisconnectDate -ne $null } | select DisplayName,DisconnectDate

MONITORING/ TROUBLESHOOTING

Test Outlook Anywhere:
Test-WebServicesConnectivity | fl

Test OWA:
Test-OwaConnectivity | fl

Test AutoDiscover:
Test-OutlookWebServices | fl

The counter Processor%Processor Time should not be consistently over 75%. Although spikes will regularly occur, if the processor is being so heavily utilized, you should consider upgrading. On an Edge Transport server, this can happen if Forefront for Exchange is deployed and the antivirus scanning engines are taking up too many of the processor’s cycles. On a server that is not under duress, the Logical DiskQueue Length counter should be 4 or lower, MemoryPages/Sec should not be regularly higher than 10, and Network InterfaceOutput Queue Length should not be higher than 5.

Mailbox servers rely heavily on the disk subsystem. On a server that is coping well with its load, the Logical DiskQueue Length counter should be 4 or lower. A rating of 15 would suggest that the volume is being used so heavily that the entire server is crawling to a halt. In this situation, you’d want to move some mailboxes off this server or put in faster disks, such as those in a striped volume. On a server that is not under duress, the counter Processor%Processor Time should not be consistently over 75%, MemoryPages/Sec should not be regularly higher than 10, and Network InterfaceOutput Queue Length should not be higher than 5.

Comments are closed for this post.