> 今天在微软的galary 中闲逛,发现了一个PS脚本,是导出当前的用户数据大小的值的,和对比一段时间数据库大小的值。我们现在不需要对比,只需要得出当前的用户的几个指标,因此我将这段PS代码修改了下,就不再需要利用EXCEL 做数据大小的计算了,代码如下,大家可以把这段代码COPY 到一个NOTEPAD中,然后保存为PS1即可。
代码语言:javascript复制#edit by raymond xu,you can contact me by sending mail wusc@wscon.cn
param
(
[Switch]$ExportMailboxSize,
[Switch]$CompareMailboxSize,
[String]$LogPath="C:log",
[String[]]$Identity,
[DateTime]$StartDate,
[DateTime]$EndDate
)
#region Export today's Mailbox Size
if ($ExportMailboxSize)
{
$Counter=0
$UserMailboxStatistics=@()
if(-not ( Test-Path -Path $LogPath))
{
New-Item -ItemType directory -Path $LogPath
}
#Get mailbox identity
if (-not ($Identity))
{
$UserMailboxs=Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -ResultSize unlimited
}
else
{
$UserMailboxs=$Identity|Get-Mailbox -Filter 'RecipientTypeDetails -eq "UserMailbox"' -ResultSize unlimited
}
#Get SamAccountName,DisplayName and MailboxTotalItemSize for specific users or all users with mailbox.
foreach ($UserMailbox in $UserMailboxs)
{
$Counter
Write-Progress -Activity "Export MailboxStatistic" -Status "Exporting" -CurrentOperation $UserMailbox.DisplayName -PercentComplete ($counter/($UserMailboxs.Count)*100)
$UserMailboxStatistic = New-Object PSObject
$UserMailboxSizeB = (Get-MailboxStatistics -Identity $UserMailbox).TotalItemSize.Value.tobytes()
$UserMailboxItem = (Get-MailboxStatistics -Identity $UserMailbox).itemcount
$UserMailboxDeleteditem=(Get-MailboxStatistics -Identity $UserMailbox).deleteditemcount
$UserMailboxDeletesizeB=(Get-MailboxStatistics -Identity $UserMailbox).TotalDeletedItemSize.Value.tobytes()
$UserMailboxSizeMB = "{0:#.##}" -f ($UserMailboxSizeB/1mb)
$UserMailboxDeletesizeMB="{0:#.##}" -f ($UserMailboxDeletesizeB/1mb)
$usermailboxstatus=(Get-MailboxStatistics -Identity $UserMailbox).StorageLimitStatus
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "SamAccountName" -Value $UserMailbox.SamAccountName
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $UserMailbox.DisplayName
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "UserMailboxSizeMB" -Value $UserMailboxSizeMB
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "MailboxItemCount" -Value $UserMailboxItem
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "MailboxDeleteditem" -Value $UserMailboxDeleteditem
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "MailboxDeletedsize" -Value $UserMailboxDeletesizeMB
$UserMailboxStatistic | Add-Member -MemberType NoteProperty -Name "Mailboxstatus" -Value $usermailboxstatus
$UserMailboxStatistics =$UserMailboxStatistic
}
#Output to a CSV file with date format "yyyy-MM-dd" as default name ,in default path "C:log". Path can be set by $logpath param.
$UserMailboxStatistics|Export-Csv -Encoding default -NoTypeInformation -Path "$LogPath$(get-date -Format "yyyy-MM-dd").csv"
}
#endregion
if (-not $ExportMailboxSize -and -not $CompareMailboxSize)
{
Write-Warning -Message "You did not choose any task. Please choose one."
}