🠪  Servers
  🠪  Testing
  🠪  Tips

  🠪  3D Printing
  🠪  Apple
  🠪  Batteries
  🠪  Drives
  🠪  Edgerouter
  🠪  Electronics
  🠪  Laptop
  🠪  Modems
  🠪  Phone
  🠪  Printers
  🠪  Raspberry Pi
  🠪  Tablets
  🠪  Testing
  🠪  Virtualization

  🠪  General

  🠪  Interesting
  🠪  Media

  🠪  Data
  🠪  Testing
  🠪  VPN

  🠪  Batch
  🠪  Linux
  🠪  Powershell

  🠪  Databases
  🠪  Misc
  🠪  Website

  🠪  Other

  🠪  Backup
  🠪  Fix Issues
  🠪  Recovery

  🠪  Editing

  🠪  HTML
  🠪  Testing

  🠪  Adjustments
  🠪  Issues
  🠪  Remote Desktop
  🠪  Security
  🠪  Slow
  🠪  Software
  🠪  Startup

Submit Entry
Airin's Notes

Category: Scripts 🠪 Powershell
Exchange Commands
December 2, 2023

Check exchange version. The best method is to visit link below and download the health check script. Alternately, the next two commands may show (get-exchangeserver may sometimes show old version).
Get-Command Exsetup.exe | ForEach {$_.FileVersionInfo}
Get-ExchangeServer | Format-List Name,Edition,AdminDisplayVersion

Get-Mailbox -Identity first.last | fl DisplayName, Name, PrimarySmtpAddress, ServerName, Database, LegacyExchangeDN, RecipientTypeDetails, RoleAssignmentPolicy, CustomAttribute10
Get-MailboxFolderStatistics -Identity first.last | ft name,foldersize,itemsinfolder -auto
Get-MailboxStatistics first.last | Select -Expand TotalItemSize
Get-InboxRule -Mailbox first.last | ft Enabled,Name -auto
Get-MailboxJunkEmailConfiguration -Identity first.last | fl Identity, Enabled, ContactsTrusted, TrustedSendersAndDomains, BlockedSendersAndDomainsGet-MailboxAutoReplyConfiguration first.last | fl AutoReplyState, ExternalMessage, InternalMessage
Get-MailboxPermission first.last | where { ($_.IsInherited -eq $False) -and -not ($_.User -like "NT AUTHORITY\SELF") } | fl Identity,User,AccessRights
Get-MailboxFolderPermission first.last | fl Identity,User,AccessRightsGet-ADPermission first.last | Where { ($_.IsInherited -eq $False) -and -not ($_.User -like "NT AUTHORITY\SELF") } | ft User, Properties, AccessRights -auto
Get-Recipient -Identity first.last | where {$_.RecipientType -eq 'MailContact'} | Select -Expand Name | Get-MailContact | fl DisplayName, PrimarySmtpAddress, Identity, LegacyExchangeDN

- Powershell (x86) 32bit - Get-Module "ActiveDirectory"

* Search share for a user *
Get-ChildItem -Path \\SERVER\USER06$ | Get-ChildItem | Where-Object {$_.Name -eq "first.last"};
$strDir = "\\server01\user01$";
$strUser = "first.last";
Get-ChildItem -Path $strDir | Get-ChildItem | Where-Object {$_.Name -eq $strUser};

* Check user information *
if(!(Get-Module "ActiveDirectory")){Import-Module ActiveDirectory}
Get-ADUser first.last -Properties * -Server SERVERDC01 | fl Name,DisplayName,telephoneNumber,EmployeeID,EmployeeType

* Set H: Path *
if(!(Get-Module "ActiveDirectory")){Import-Module ActiveDirectory}
Set-ADUser first.last -server SERVERDC01 -HomeDrive "H" -HomeDirectory \\SERVERFS01\first.last

* Compare Folders *
$fso = Get-ChildItem -path "C:\Program Files (x86)\Hewlett-Packard\HPCA\Agent"
$fsoBU = Get-ChildItem -path "\\%machine%\c$\Program Files (x86)\Hewlett-Packard\HPCA\Agent"
Compare-Object -ReferenceObject $fso -DifferenceObject $fsoBU

* Compare folders AND subfolders *
$fso = Get-ChildItem -Recurse -path "C:\Program Files (x86)\Hewlett-Packard\HPCA\Agent"
$fsoBU = Get-ChildItem -Recurse -path "\\%machine%\c$\Program Files (x86)\Hewlett-Packard\HPCA\Agent"
Compare-Object -ReferenceObject $fso -DifferenceObject $fsoBU

* Public Folders *
Get-PublicFolder -Identity \sub -Recurse -ResultSize 100 | fl Replicas,Identity
Get-PublicFolder -Identity \sub -Recurse -ResultSize 100 | Export-CSV "C:\Public.csv"
Get-PublicFolder -Identity \sub -getchildren
Get-PublicFolder -Identity "\sub\sub\folder" -getchildren
Get-PublicFolder -identity "\sub\sub\folder\etc" -recurse | fl *

* Check Public Folder Permissions
Get-PublicFolderClientPermission -Identity "\sub\folder\etc" | fl
Get-PublicFolderClientPermission -Identity "\sub\folder\etc" -User first.last | Format-List

Set-ExecutionPolicy Unrestricted

* Connect to Exchange server**
powershell -noexit -command Set-ExecutionPolicy Unrestricted; $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "http://serverex01/PowerShell/" -Authentication Kerberos ; Import-PSSession $Session -AllowClobber ; Set-ADServerSettings -ViewEntireForest $true ; Set-ADServerSettings -PreferredServer serverdc01

* Move AD Account to different domain: *
Import-Module ActiveDirectory
Get-ADUser -Server "serverex01" -Identity "" | Move-ADObject -Server "serverdc01" -TargetPath "OU=USERS,OU=PTGN,OU=CNO,DC=server01,DC=test,DC=com" -TargetServer "serverdc01"

* Get server Stats *
Get-MailboxDatabase -Server serverex01 | fl *

* Get email statistics *
Get-Mailbox -Identity first.last
Get-MailboxStatistics -Identity "first.last" | Format-List
Get-Mailbox -Identity "first.last" | fl EmailAddressPolicyEnabled, EmailAddresses

* Check if Out OF Office reply is turned on (AutoReplyState) *
Get-MailboxAutoReplyConfiguration -Identity "first.last"

* Disable Out Of Office *
Set-MailboxAutoReplyConfiguration -Identity "first.last" -AutoReplyState disabled

* Disable Out of Office and clear the messages *
Set-MailboxAutoReplyConfiguration -Identity "first.last" -AutoReplyState disabled -InternalMessage "" -ExternalMessage ""

* Enable Out Of Office *
Set-MailboxAutoReplyConfiguration -Identity "first.last" -AutoReplyState enabled

* Create mailbox for user *
Enable-Mailbox "first.last" -Alias "first.last" -Database "exch-data-base"
set-Mailbox first.last -ApplyMandatoryProperties

* Remove an email address for a user *
Set-Mailbox -Identity "first.last" -EmailAddresses @{remove=""}

* Add an email address for a user *
Set-Mailbox -Identity "first.last" -EmailAddresses @{add=""}

* Set default SMTP address for a user *
Set-Mailbox -EmailAddresses SMTP : ,

* Find all accounts about to be deleted *
Get-MailboxStatistics -Database exch-data-base | Where { $_.DisconnectReason -eq "SoftDeleted" } | `
Format-List LegacyDN, DisplayName, MailboxGUID, DisconnectReason

* Show any serverside mailbox rules for a user *
Get-InboxRule -Mailbox first.last

* Move a mailbox to a new server *
New-MoveRequest -Identity first.last -TargetDatabase exch-data-base -BadItemLimit 100 -AcceptLargeDataLoss

* Show status of move *
Get-MoveRequestStatistics -Identity first.last | fl Status,StatusDetail,PercentComplete,BytesTransferred,TotalMailboxSize,BadItemsEncountered,LastUpdateTimestamp
Get-MoveRequestStatistics -Identity first.last | Format-List

*Adds AD Permission for mailbox to User:
Add-ADPermission "mailbox" -User "username" -AccessRights WriteProperty -Properties Personal-Information

Add-MailboxPermission -Identity "first.last" -User "first.last" -AccessRights FullAccess,DeleteItem -InheritanceType All

Remove-MailboxPermission -Identity "first.last" -User "first.last" -AccessRights FullAccess,DeleteItem,ReadPermission,ChangePermission,ChangeOwner -InheritanceType All

**Adds Send On Behalf rights
Set-Mailbox "" -GrantSendOnbehalfto @{Add=""}
Set-Mailbox "" -GrantSendOnbehalfto @{Remove=">"}

**sets mailbox share/regular
Set-Mailbox "mailbox display name" -Type:Regular

This site is meant to be used as a reference for myself, although others may find it useful. I use it to keep track of certain fixes, software, and other solutions which I may need while assisting customers. The page layout is pure HTML/CSS and is kept simple to optimize loading time and fast results.

Return to Airin's Computers