Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSScriptAnalyzer cleanup and typo fix #9

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Office365/MailboxSizeReport.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ Function ConnectTo-EXO {

process {
# Check if EXO is installed and connect if no connection exists
if ((Get-Module -ListAvailable -Name ExchangeOnlineManagement) -eq $null)
if ($null -eq (Get-Module -ListAvailable -Name ExchangeOnlineManagement))
{
Write-Host "Exchange Online PowerShell v2 module is requied, do you want to install it?" -ForegroundColor Yellow
Write-Host "Exchange Online PowerShell v2 module is required, do you want to install it?" -ForegroundColor Yellow

$install = Read-Host Do you want to install module? [Y] Yes [N] No
if($install -match "[yY]")
Expand All @@ -92,7 +92,7 @@ Function ConnectTo-EXO {
}


if ((Get-Module -ListAvailable -Name ExchangeOnlineManagement) -ne $null)
if ($null -ne (Get-Module -ListAvailable -Name ExchangeOnlineManagement))
{
# Check if there is a active EXO sessions
$psSessions = Get-PSSession | Select-Object -Property State, Name
Expand Down Expand Up @@ -120,7 +120,7 @@ Function Get-Mailboxes {
}

Get-EXOMailbox -ResultSize unlimited -RecipientTypeDetails $mailboxTypes -Properties IssueWarningQuota, ProhibitSendReceiveQuota, ArchiveQuota, ArchiveWarningQuota, ArchiveDatabase |
select UserPrincipalName, DisplayName, PrimarySMTPAddress, RecipientType, RecipientTypeDetails, IssueWarningQuota, ProhibitSendReceiveQuota, ArchiveQuota, ArchiveWarningQuota, ArchiveDatabase
Select-Object UserPrincipalName, DisplayName, PrimarySMTPAddress, RecipientType, RecipientTypeDetails, IssueWarningQuota, ProhibitSendReceiveQuota, ArchiveQuota, ArchiveWarningQuota, ArchiveDatabase
}
}

Expand Down Expand Up @@ -160,20 +160,20 @@ Function Get-MailboxStats {
$mailboxes = Get-Mailboxes
$i = 0

$mailboxes | ForEach {
$mailboxes | ForEach-Object {

# Get mailbox size
$mailboxSize = Get-MailboxStatistics -identity $_.UserPrincipalName | Select TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount,LastUserActionTime
$mailboxSize = Get-MailboxStatistics -identity $_.UserPrincipalName | Select-Object TotalItemSize,TotalDeletedItemSize,ItemCount,DeletedItemCount,LastUserActionTime

if ($mailboxSize -ne $null) {
if ($null -ne $mailboxSize) {

# Get archive size if it exists and is requested
$archiveSize = 0
$archiveResult = $null

if ($archive.IsPresent -and ($_.ArchiveDatabase -ne $null)) {
$archiveResult = Get-EXOMailboxStatistics -UserPrincipalName $_.UserPrincipalName -Archive | Select ItemCount,DeletedItemCount,@{Name = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Split("(")[0]}}
if ($archiveResult -ne $null) {
if ($archive.IsPresent -and ($null -ne $_.ArchiveDatabase)) {
$archiveResult = Get-EXOMailboxStatistics -UserPrincipalName $_.UserPrincipalName -Archive | Select-Object ItemCount,DeletedItemCount,@{Name = "TotalArchiveSize"; Expression = {$_.TotalItemSize.ToString().Split("(")[0]}}
if ($null -ne $archiveResult) {
$archiveSize = ConvertTo-Gb -size $archiveResult.TotalArchiveSize
}else{
$archiveSize = 0
Expand Down