Add a trusted domain to everyone in exchange - powershell

Currently we have an HR email going out to the all of our staff. By default, the email gets sorted into the junk email for everyone.
I'd like to use the PowerShell cmdlet Set-MailboxJunkEmailConfiguration to add the sending domain as a trusted domain to everyone without having to set it individually for every person.
I know I need to use
Set-MailboxJunkEmailConfiguration DomainGoesHere -TrustedSendersAndDomains #{Add="whatever#abc123.com")
However I don't know what I need to add to target everyone in my domain.
Any help so I don't have to change this for hundreds of users by hand.
I ran the following command
Get-Mailbox -ResultSize unlimited -RecipientTypeDetails UserMailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains #{Add="mysafedomain.com"}
and get the following error
The Junk E-Mail configuration couldn't be set. The user needs to sign in to Outlook Web App before they can modify their Safe Senders and Recipients or Blocked Senders list.
+ CategoryInfo : NotSpecified: (545:Int32) [Set-MailboxJunkEmailConfiguration], DataSourceOperationException
+ FullyQualifiedErrorId : 47A2E998,Microsoft.Exchange.Management.StoreTasks.SetMailboxJunkEmailConfiguration
Here is the code that worked for me, thanks to Booga Roo
Get-Mailbox -ResultSize unlimited -RecipientTypeDetails UserMailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains #{Add="myTrustedDomain.com"} -ErrorAction SilentlyContinue

Thankfully Set-MailboxJunkEmailConfiguration accepts pipeline input for -Identity.
This should do it(replace the domain names, of course):
Get-Mailbox -ResultSize unlimited -RecipientTypeDetails UserMailbox | Set-MailboxJunkEmailConfiguration -TrustedSendersAndDomains #{Add="contoso.com","fabrikam.com"} -ErrorAction SilentlyContinue
Now with correct placement of the }.

Related

Exchange Powershell : Is it possible to differentiate on prem and cloud based distribution group?

I'm trying to create a script that must count the number of cloud and on prem based distribution group in a hybrid Exchange setup (on-prem + office 365).
I already did that with the users mailbox, it's possible to differentiate them by using the RecipientTypeDetails attribute. A "UserMailBox" represents an on prem user and a "MailUser" represents a cloud user.
Is there something similar for distribution group ? I didn't find the answer.
Thank your for your help, regards
I finally found the answer. Here are the cmdlets used by type of mailboxes :
"USER_ONPREM" = (Get-Mailbox -Resultsize Unlimited -RecipientTypeDetails "UserMailbox").Count
"USER_CLOUD" = (Get-Recipient -Resultsize Unlimited -RecipientTypeDetails "RemoteUserMailbox").Count
"SHARED_ONPREM" = (Get-Mailbox -Resultsize Unlimited -RecipientTypeDetails "SharedMailbox").Count
"SHARED_CLOUD" = (Get-Recipient -Resultsize Unlimited -RecipientTypeDetails "RemoteSharedMailbox").Count
"EQUIPMENT_ONPREM" = (Get-Mailbox -Resultsize Unlimited -RecipientTypeDetails "EquipmentMailbox").Count
"EQUIPMENT_CLOUD" = (Get-Recipient -Resultsize Unlimited -RecipientTypeDetails "RemoteEquipmentMailbox").Count
"ROOM_ONPREM" = (Get-Mailbox -Resultsize Unlimited -RecipientTypeDetails "RoomMailbox").Count
"ROOM_CLOUD" = (Get-Recipient -Resultsize Unlimited -RecipientTypeDetails "RemoteRoomMailbox").Count
"DL_ONPREM" = (Get-DistributionGroup -Resultsize Unlimited | where {$_.IsDirSynced -eq $False}).Count
"DL_CLOUD" = (Get-DistributionGroup -Resultsize Unlimited | where {$_.IsDirSynced -eq $True}).Count
To get on-prem mailboxes, it's just needed to use Get-Mailbox and filter by type.
To get remote mailboxes (i.e. mailboxes that are synced/migrated from onprem environment) it's possible to use Get-RemoteMailbox or Get-Recipient and filter by type with the suffix "Remote" added.
Finally to get "cloud only" mailboxes, it's only possible to retrieve them using an Exchange Online connection and from there we can verify which mailboxes are not synced with the attribute $_.IsDirSynced.
More infos : https://learn.microsoft.com/en-us/answers/questions/594318/exchange-powershell-is-it-possible-to-differentiat.html
When onPrem IsDirSynced indicates if the mailbox is synced to the cloud and when in the cloud IsDirSynced indicates if the mailbox is synced to on prem. Not very intuitive, but hey, it's Microsoft I guess.
I compared the result with what the ECP returns (The ECP classifies account as OnPrem or Office 365) and the numbers are correct.

Is there a command to verify if MAPI is enabled for all users?

We have an organization in our Exchange services (2016) which has well above 200 users.
We need to verify if MAPI is enabled for each of them, and if not, who doesn't have it so we can enable it...
Is there a Powershell/ExchangeShell command which :
Lists all users who have MAPI enabled under an organization (we could then compare who's missing, it would already be much faster)?
List all users, and which APIs or protocols they have enabled (POP, IMAP, OWA, MAPI, etc.)?
Any of those would be of great help, so far I've only found a command in which you search for one user, but I don't want to have to do that for all 200 users...
This is fairly straight forward since most Exchange cmdlets allow piping directly into other Exchange cmdlets.
List all users, and which APIs or protocols they have enabled:
Get-CASMailbox -ResultSize unlimited
Possibly more useful to you is a list in CSV format since 200 users is tough to sort through in the PowerShell console. This will list more protocols and features, adjust as needed:
Get-CASMailbox -ResultSize unlimited | Select-Object -Property Identity, *Enabled | Export-Csv -NoTypeInformation -Path report.csv
List all users who have MAPI enabled:
Get-CASMailbox -ResultSize unlimited | where {$_.MapiEnabled -match "true"}
List all users who don't have MAPI enabled and enable it. Remove -WhatIf when ready to run it for real:
Get-CASMailbox -ResultSize unlimited | where {$_.MapiEnabled -match "False"} | Set-CASMailbox -MAPIEnabled $true -WhatIf
Note, this was run against an Exchange Online organization(where MAPI is enabled by default). You might need to use Get-CASMailbox -OrganizationalUnit <OrgName> or other filters to make sure you're only dealing with the correct mailboxes.

Powershell script to list all users that have message delivery restrictions in exchange 2010

Get-Mailbox -Filter {AcceptMessagesOnlyFrom -ne $Null}
This code only return few users and it shows ProhibitSendQuota,
I would like to return all users that have message delivery restrictions configured to accept messages from and reject messages from.
*Additional info: the users are located in sample.net/sample DIV OU/IDM_Users
Looking back through my Exchange Scripts, I have this for getting Delivery Restrictions:
Get-Mailbox –ResultSize Unlimited |
Where-Object {$_.AcceptMessagesOnlyFromSendersOrMembers –ne "" –or $_.RejectMessagesFromSendersOrMembers –ne ""} |
Select Name,Alias,AcceptMessagesOnlyFromSendersOrMembers,RejectMessagesFromSendersOrMembers
I'm not able to test it as I don't use Exchange anymore, but it should still be correct.
I managed to solve it by using the following query.
Get-Mailbox -ResultSize Unlimited -OrganizationalUnit "OU=SAMPLE DIV OU ,DC=SAMPLE,DC=NET" |
where-object {$_.AcceptMessagesOnlyFromSendersOrMembers –ne “” –or $_.RejectMessagesFromSendersOrMembers –ne “”} |
select Name, alias, AccpetMessagesOnlyFromSendersOrMembers, RejectMessagesFromSendersOrMembers
The Get-Mailbox cmdlet has a -OrganizationalUnit parameter that I used to target the OU.

Get-mailboxstatistics from all Office 365 Mailboxes

I need the LastLogonTime from all our cloud hosted mailboxes. Google tells me to
Get-Mailbox | Get-MailboxStatistics
Get-Mailbox currently returns 2172 mailboxes but when returning the entire object to Get-MailboxStatistics, it's giving an error on 59 mailboxes: The specified mailbox "Firstname Lastname" isn't unique.
For some of these mailboxes I can indeed find a Mailbox with a duplicate DisplayName but not for all.
So there are some Mailboxes without a valid Get-MailboxStatistics result. But when I ask the Get-MailboxStatistics from the ExchangeGuid, the record IS returned. I.e.
Get-MailboxStatistics -Identity 7045326a-5c0f-4a84-aa0c-ceb$$$$c67fe
When I modify my script to loop the mailbox results and query the statistics for each mailbox, I get the (obvious) response: The request is not serviced on the server. Your request is too frequent. Please wait for few minutes and retry again.
So.. my question is..
How do I pipe the ExchangeGuid of every Get-Mailbox record to the Get-MailboxStatistics?
Get-Mailbox -ResultSize 5 | Select-Object ExchangeGuid | Get-MailboxStatistics
returns:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline in put or the input and its properties do not match any of the parameters that take pipeline input.
+ CategoryInfo : InvalidArgument: (#{ExchangeGuid=...5-684390d4a758}:PSObject) [Get-MailboxStatistics], P arameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,Get-MailboxStatistics
+ PSComputerName : outlook.office365.com
You can try to use the UPN (User Principal Name) which is unique :
get-mailbox -ResultSize 5 |select -expand userprincipalname |Get-MailboxStatistics

How to find all users on Exchange server from a particular OU?

I need to get a report of all users on an Exchange server who are located at one particular OU in Active Directory. Is there a way to do this with Powershell or VBS?
Thanks
Get-Mailbox -ResultSize Unlimited -OrganizationalUnit 'OU=test1,DC=domain,DC=com'
The PS cmdlet will work for versions of Exchange 2007 and later.
Here is how you'd extract the list and dump it in a text file. I've added the -IgnoreDefaultScope handle so that you're able to extract the list even though the OU in question is in a subdomain.
Get-Mailbox -IgnoreDefaultScope -ResultSize Unlimited -OrganizationalUnit 'OU=Staff Leavers,DC=my,DC=domain,DC=com' > C:\SysMgr\LeaverMailboxes.txt