Guide Programming + Scripting Powershell Exchange Commands Updated August 11 2024
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
https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019

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"};
or
$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 *
http://technet.microsoft.com/en-us/library/cc788135(v=exchg.80).aspx

* 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 "user.name" | 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="email@isp.net"}


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


* Set default SMTP address for a user *
Set-Mailbox user.name -EmailAddresses SMTP : first.last@isp.net , othermail@isp.net


* 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 "mailbox.name" -GrantSendOnbehalfto @{Add="user.name"}
Set-Mailbox "mailbox.name" -GrantSendOnbehalfto @{Remove="user.name>"}

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




Install ExchangeOnlineManagement if it isn't yet installed (run as Admin):
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 3.4.0

Import module:
Import-Module ExchangeOnlineManagement

Connect-ExchangeOnline -UserPrincipalName user@yourdomainhere.com
Enable-OrganizationCustomization


Install ExchangeOnlineManagement
https://www.powershellgallery.com/packages/ExchangeOnlineManagement/3.4.0


Enable Forwarding for all accounts:
Remote Server returned '550 5.7.520 Access denied, Your organization does not allow external forwarding. Please contact your administrator for further assistance. AS(7555)'. Please advise, this is a show stopper high priority ticket. Please escalate.
https://learn.microsoft.com/en-us/answers/questions/465091/how-to-enable-organization-customization
Connect-ExchangeOnline -UserPrincipalName youremailher@yourdomainhere.com
Enable-OrganizationCustomization
Set-HostedOutboundSpamFilterPolicy -Identity Default -AutoForwardingMode On
Get-HostedOutboundSpamFilterPolicy -Identity Default


Keywords: Microsoft Online Exchange Hosted, Email Forwarding, E-Mail, Rule




©2024 - Some portions of this website are Copyrighted.
Your IP: 18.216.42.122     Referring URL:
Browser: Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Terms and Conditions, Privacy Policy, and Security Policy