Powershell 脚本用于从 OU 获取共享邮箱及其上次访问时间和大小

Powershell 脚本用于从 OU 获取共享邮箱及其上次访问时间和大小

我目前正在尝试生成系统上所有共享邮箱的列表,包括每个邮箱的上次访问时间和大小。许多“共享邮箱”都是作为普通邮箱创建的,并授予许多用户访问权限。目前这是我的脚本,但我甚至没有创建 test.csv。

获取邮箱 -Org “域/x/x/共享邮箱” | 获取邮箱统计信息 | 按上次登录时间排序 -descending| 选择显示名称,最后* | 导出 Csv C:\test.csv -NoTypeInformation

有人可以帮忙吗?

答案1

您确定您正确使用了 cmldets 吗?请查看帮助文件和示例。

https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/get-mailbox?view=exchange-ps https://docs.microsoft.com/en-us/powershell/module/exchange/mailboxes/get-mailboxstatistics?view=exchange-ps

# get function / cmdlet details
Get-Command -Name Get-Mailbox -Syntax
(Get-Command -Name Get-Mailbox).Parameters.Keys
Get-help -Name Get-Mailbox -Full
Get-help -Name Get-Mailbox -Online
Get-help -Name Get-Mailbox -Examples

Get-Command -Name Get-MailboxStatistics -Syntax
(Get-Command -Name Get-MailboxStatistics).Parameters.Keys
Get-help -Name Get-MailboxStatistics -Full
Get-help -Name Get-MailboxStatistics -Online
Get-help -Name Get-MailboxStatistics -Examples

如果您没有得到任何结果,那只是意味着您的脚本结果为空。永远不要结束整个脚本。始终、始终一次遍历一个片段,以确保您获得您认为应该获得的结果,将写入文件的内容留到屏幕上显示所有内容为止。因此,暂时注释掉或删除 Export-Csv 内容,直到您弄清楚为什么什么都没有得到。

# Step one
Get-Mailbox -Org "domain/x/x/Shared Mailboxes"
# Are results returned - of not, stop and figure out why.

# Step 2
Get-Mailbox -Org "domain/x/x/Shared Mailboxes" | Get-MailboxStatistics 
# Are results returned - of not, stop and figure out why.

# if the above either of the above fail, then all else does not matter.

# Get all mailboxes for the specified OU
Get-Mailbox -OrganizationalUnit $((Get-ADOrganizationalUnit -Filter '*').DistinguishedName[3])

# Get mailbox for the specified OU, for a specified user in that OU
(Get-Mailbox -OrganizationalUnit $((Get-ADOrganizationalUnit -Filter '*').DistinguishedName[3])).Alias[3]

# Get mailbox for the specified OU, for a specified user statistics in that OU
(Get-Mailbox -OrganizationalUnit $((Get-ADOrganizationalUnit -Filter '*').DistinguishedName[3])).Alias[3] | 
Get-MailboxStatistics

# Get all the statistics info, for all mailboxes, selecting only the fields of interest
Get-Mailbox -OrganizationalUnit $((Get-ADOrganizationalUnit -Filter '*').DistinguishedName[3]) | 
Get-MailboxStatistics | 
Sort-Object LastLogonTime -descending | 
Select-Object DisplayName,LastLogonTime 

相关内容