$recipientType = @{
1 = ‘UserMailbox’
2 = ‘Linked Mailbox’
4 = ‘Shared Mailbox’
8 = ‘Exchange 2003 Legacy’
16 = ‘Room’
32 = ‘Equipment’
64 = ‘Mail Contact’
128 = ‘Mail User’
256 = ‘Mail universal Distribution Group’
512 = ‘Mail non universal Group’
1024 = ‘Mail universal Security Group’
2048 = ‘Dynamic Distribution Group’
4096 = ‘Mail-Enabled Public Folder’
8192 = ‘System Attendant Mailbox’
16384 = ‘Systemmailbox/Mailbox Database Mailbox’
32768 = ‘Cross Forest Mail Contact’
65536 = ‘User’
131072 = ‘Contact’
262144 = ‘Universal Distribution Group’
524288 = ‘Universal Security Group’
1048576 = ‘Non-Universal Group’
2097152 = ‘Disabled User’
4194304 = ‘Microsoft Exchange’
8388608 = ‘Arbitration Mailbox’
16777216 = ‘MailboxPlan’
33554432 = ‘LinkedUser’
268435456 = ‘RoomList’
536870912 = ‘DiscoverySearchMailbox’
1073741824 = ‘Role Group’
2147483648 = ‘RemoteUserMailbox’
4294967296 = ‘Computer’
8589934592 = ‘RemoteRoomMailbox’
17179869184 = ‘RemoteEquipmentMailbox’
34359738368 = ‘RemoteSharedMailbox’
68719476736 = ‘PublicFoldermailbox’
137438953472 = ‘Team Mailbox’
274877906944 = ‘RemoteTeamMailbox’
549755813888 = ‘Monitoring Mailbox’
1099511627776 = ‘Group Mailbox’
2199023255552 = ‘LinkedRoomMailbox’
4398046511104 = ‘AuditLogMailbox’
8796093022208 = ‘RemoteGroupMailbox’
17592186044416 = ‘SchedulingMailbox’
35184372088832 = ‘GuestMailBox’
70368744177664 = ‘AuxAuditLogMailbox’
140737488355328 = ‘SupervisoryReview’
}
$date = (Get-Date).AddDays(-180) //统计180天内未登录用户
$properties = @(
'canonicalName'
'Enabled'
'LastLogonDate'
'whenCreated'
'msExchRecipientTypeDetails'
'userPrincipalName'
'SamAccountName'
'mailNickname'
'ProxyAddresses'
'displayName'
'givenName'
'sn'
'title'
'department'
'physicalDeliveryOfficeName'
'telephoneNumber'
'mobile'
'streetAddress'
'l'
'st'
'postalCode'
'c'
)
Use -notlike “*” for empty/no mailboxes
Get-ADUser -Filter ‘ProxyAddresses -like “*” -and lastLogonDate -lt $date’ -Properties $properties -ResultSetSize 2000 |
ForEach-Object {
[PSCustomObject]@{
Path = $_.CanonicalName
'AD Status' = ('Disabled', 'Enabled')[[Int32]$_.Enabled]
LastLogonDate = $_.LastLogonDate
WhenCreated = $_.WhenCreated
RecipientType = $(if ($_.msExchRecipientTypeDetails) {$recipientType[$_.msExchRecipientTypeDetails]})
userPrincipalName = $_.userPrincipalName
SamAccountName = $_.SamAccountName
mailNickname = $_.mailNickname
Primaryemail = $_.ProxyAddresses -cmatch '^SMTP:' -replace '^smtp:'
ProxyAddresses = $_.ProxyAddresses
displayName = $_.displayName
givenName = $_.givenName
sn = $_.sn
title = $_.title
department = $_.department
physicalDeliveryOfficeName = $_.physicalDeliveryOfficeName
telephoneNumber = $_.telephoneNumber
mobile = $_.mobile
streetAddress = $_.streetAddress
l = $_.l
st = $_.st
postalCode = $_.postalCode
c = $_.c
}
} |
Export-Csv $home\desktop\Inactivembxreport.csv -NoTypeInformation -Encoding Utf8

