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
Related
I've been trying to do this for a while now. When Exchange mailboxes are disabled or soft-deleted they are disconnected from their AD user account object. We can reconnect them if we want to but is there a way to identify the AD user account it was associated with before disconnect ?.
I'm not an on-prem Exchange Administrator but have the necessary access for Recipient Configuration.
I've been able to use the displayName property from Get-MailboxStatistics results, but displayName is not a unique attribute (like distinguishedname, for instance).
I'm connecting to Exchange Server 2013 via PowerShell remote PSSession.
I know LastLoggedOnUserAccount property is no longer an option with 2013.
I see Mailbox auditing can help but this needs to be enabled per mailbox, this is out of my work scope and might add a big overhead in large organizations
Search-MailboxAuditLog cmdlet is not visible for me in PowerShell my Exchange Management session
Any solution/workaround would be very much appreciated.
I cannot test this myself, but there is a property returned by Get-MailboxStatistics you could use, which is called MailboxGuid.
Below should get you a list of disconnected mailboxes where besides the DisplayName, the users EmailAddress and DistinghuishedName is returned.
Get-MailboxStatistics | Where-Object { $_.DisconnectReason } | ForEach-Object { # get disconected mailboxes
$email = Get-User -Identity $_.MailboxGuid.Guid | Select-Object -ExpandProperty WindowsEmailAddress
$userDN = Get-Mailbox -Identity $email | Select-Object -ExpandProperty DistinguishedName
Select-Object DisconnectDate, DisconnectReason, DisplayName,
#{Name = "EmailAddress"; Expression = { $email }},
#{Name = "DistinguishedName"; Expression = {$userDN }}
}
I want to get office365 mailbox list which Last logon was more than 180 days? and export their .pst files to another location?
Wrote this script
But i am receiving error like - A parameter cannot be found that matches parameter name 'resultsize'
cant find where is the problem...
Get-MailboxStatistics -resultsize unlimited |
Where-Object {$_.LastLogonTime -lt (get-date).AddDays(-180)} |
Format-Table displayName,lastlogontime,lastloggedonuseraccount,servername
Get-MailboxStatistics has no -ResultSize argument. You should retrieve the mailboxes with Get-Mailbox and pipe results to get the statistics:
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics
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.
With PowerShell, I want to make an export of all the mailboxes in an Exchange environment of users in a specific OU where the level of AccessRights of the user "Default" on the folder level does not equal "None". For this I am using the following command:
$AllMailbox = Get-Mailbox -OrganizationalUnit "DNofOU" -ResultSize Unlimited
$ResultData = foreach ($Mailbox in $AllMailbox)
{
Get-MailboxFolderPermission $Mailbox | Where-Object {$_.User -Match "Default" -AND $_.AccessRights -NotMatch "None"} | Select-Object Identity,AccessRights,#{Name="Name"; Expression={$Mailbox.Name}}
}
$ResultData | Export-CSV -Path C:\temp\MailboxFolderPermissions.csv
However, when running this command I get the following error:
Cannot process argument transformation on parameter 'Identity'. Cannot convert the "DisplayNameOfMailbox" value of type "Deserialized.Microsoft.Exc
hange.Data.Directory.Management.Mailbox" to type "Microsoft.Exchange.Configuration.Tasks.MailboxFolderIdParameter".
+ CategoryInfo : InvalidData: (:) [Get-MailboxFolderPermission], ParameterBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Get-MailboxFolderPermission
+ PSComputerName : FQDNofExchangeServer
The environment is based on Exchange 2010 on a Windows Server 2008 R2 server with PowerShell version 2.0. It is also possible to execute this from a Windows Server 2012 R2 server with PowerShell version 4.0 when remote connecting to the Exchange server.
For me, it worked better to use the full Canonical name of the object.
Like so:
$mailboxArray = Get-Mailbox -OrganizationalUnit "example.com/Accounts" -ResultSize Unlimited
I Wasn't sure if this for have found the answer or not yet, but wanted to provide my input on how you could possibly get all the mailboxes in an organizational Unit.
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 }.