Thursday, 26 December 2024

SFB Health Check

[array]$AllUserPools    = @(Get-CsService -UserServer | Select-Object -ExpandProperty PoolFqdn)
[array]$AllEdgePools    = @(Get-CsService -EdgeServer | Select-Object -ExpandProperty PoolFqdn)
[array]$AllFileStores   = @(Get-CsService -FileStore | Select-Object -ExpandProperty UncPath)
[array]$AllSQLServers   = @(Get-CsService -ApplicationDatabase | Select-Object -ExpandProperty PoolFqdn)
[array]$AllSFBServers  = @()
[array]$AllEdgeServers  = @()
# Dynamically builds list of all SfB Servers based on pools
foreach ($pool in $AllUserPools)
{
    $AllSFBServers += Get-CsComputer -Pool $pool | Select-Object -ExpandProperty Fqdn
}
$AllSfBServers  += "Server01"
$AllSfBServers  += "Server02"
$AllSfBServers  += "Server03"
$AllSfBServers  += "Server04"
$AllSfBServers   = $AllSfBServers | Sort-Object
# Dynamically builds list of Edge servers based on Edge pools
foreach ($pool in $AllEdgePools)
{
    $AllEdgeServers += Get-CsComputer -Pool $pool | Select-Object -ExpandProperty Fqdn
}
# Sorts $AllEdgeServers by Name
$AllEdgeServers = $AllEdgeServers | Sort-Object
#endregion


###################################### Checking Services
 
$AllServerServiceStatus = [system.collections.arraylist]@()
$AllServerServiceStatus.Clear()
foreach ($server in $AllSfBServers)

    Write-Host "$server" -ForegroundColor Yellow
    #$CurrentServiceStatus = Get-CsWindowsService -ComputerName $server | select-object Name, Status
    $ServiceStatus = Get-CsWindowsService -ComputerName $server
    $(if(($ServiceStatus|Where-Object{$_.status -ne "Running"}).Count -gt 0){
        $RunningStatus = "Not Running"
    }
    else{
        $RunningStatus = "Running"
    })
    $ServiceProperty=[pscustomobject][ordered]@{
            Server = $server
            Status = $RunningStatus
    }
    $AllServerServiceStatus.Add($ServiceProperty)
}
$AllServerServiceStatus 


###################################### Testing if SQL Servers respond to connectivity test
$SQLServerPINGStatus = [system.collections.arraylist]@()
$SQLServerPINGStatus.Clear()
foreach ($sql in $AllSQLServers)
{    
    if ((Test-Connection -ComputerName $sql -Count 2 -Quiet) -eq $true)
    {
       $PingStatus = [pscustomobject][ordered]@{
            Server = $Sql
            Status = "Healthy"
       }
       $SQLServerPINGStatus.Add($PingStatus)
    }
    else
    {
       $PingStatus = [pscustomobject][ordered]@{
            Server = $Sql
            Status = "Unhealthy"
       }
       $SQLServerPINGStatus.Add($PingStatus)
    }
}
$SQLServerPINGStatus

###################################### Checks availability of each pool's file share
$PoolFileShareAvailability = [system.collections.arraylist]@()
$PoolFileShareAvailability.Clear()
foreach ($store in $AllFileStores)
{
    $test = Test-Path -Path $store
    if ((Test-Path -Path $store) -eq $true){
        $AvailabilityStatus = [pscustomobject][ordered]@{
            FileShare = $store
            Status = "Healthy"
        }
        $PoolFileShareAvailability.Add($AvailabilityStatus)
    }
    else{
       $AvailabilityStatus = [pscustomobject][ordered]@{
            FileShare = $store
            Status = "Unhealthy"
       }
       $PoolFileShareAvailability.Add($AvailabilityStatus)
    }
}
$PoolFileShareAvailability

###################################### Checks all servers for up to topology replication
$ReplicationService = [system.collections.arraylist]@()
$ReplicationService.Clear()
$replServers = Get-CsManagementStoreReplicationStatus | Sort-Object ReplicaFqdn
foreach ($replServer in $replServers)
{              
    if ($replServer.UpToDate -eq "True"){
        $ReplicationServiceStatus = [pscustomobject][ordered]@{
            Server = $replServer.ReplicaFqdn
            UpToDate = "True"
            LastStatusReport = $replServer.LastStatusReport
            Status = "Healthy"
        }
        $ReplicationService.Add($ReplicationServiceStatus)
    }
    else
    {
        $ReplicationServiceStatus = [pscustomobject][ordered]@{
            Server = $replServer.ReplicaFqdn
            UpToDate = "False"
            LastStatusReport = $replServer.LastStatusReport
            Status = "UnHealthy"
        }
        $ReplicationService.Add($ReplicationServiceStatus)
    }

$ReplicationService

###################################### Get Active User Count
$ActiveUserCount = [system.collections.arraylist]@()
$ActiveUserCount.Clear()
$UserCount = get-csuser -ResultSize unlimited | group-object -Property registrarpool | Select-Object name,Count |Sort-Object -Property count
@($UserCount | select -SkipLast 1).ForEach({
    $Property = [pscustomobject][ordered]@{
        Name = $_.Name
        Count = $_.Count
    }
    $ActiveUserCount.Add($Property)
})
$Val = $UserCount | select -Last 1| Select @{n="Name";e={'Microsoft Teams'}},@{n="Count";e={$_.Count}}
$ActiveUserCount.Add($Val)
$ActiveUserCount

###################################### SFB Server Disk Size Report
$DiskSize = [system.collections.arraylist]@()
$DiskSize.Clear()
$AllSfBServers = $AllSfBServers |Where-Object{$_ -notmatch "CMS001"}
foreach($server in $AllSfBServers){
    $Size = Get-WmiObject Win32_LogicalDisk -ComputerName $server | where{$_.DriveType -eq '3'} `
    | Select DeviceID, DriveType,VolumeName,@{N='TotalSize(GB)';E={[Math]::Ceiling($_.Size/1GB)}}, `
    @{N='FreeSize(GB)';E={[Math]::Ceiling($_.FreeSpace/1GB)}}
    #$Size = $Size | Where-Object{$_.DeviceId -eq "c:"}
    @($Size).ForEach({
        $SizeDetails = [pscustomobject][ordered]@{
            Server = $server
            Drive = $_.DeviceID
            "TotalSize(GB)" = $_.'TotalSize(GB)'
            "FreeSize(GB)"  = $_.'FreeSize(GB)'
            "Available"       =[String]([Math]::Round(([Int]($_.'FreeSize(GB)') / [Int]($_.'TotalSize(GB)')) * 100)) + " %"
        }
        $DiskSize.Add($SizeDetails)
    })
    $SizeDetails = [pscustomobject][ordered]@{
            Server = ""
            Drive = ""
            "TotalSize(GB)" = ""
            "FreeSize(GB)"  = ""
            "Available"     = ""
    }
    $DiskSize.Add($SizeDetails)
}
$DiskSize | ft

$head = @"
<style>
h1, h5, th { text-align: center; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; }
th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even) { background: #dae5f4; }
tr:nth-child(odd) { background: #b8d1f3; }
</style>
"@

if(($AllServerServiceStatus.Status -ne "Running").Count -gt 0){$Report_AllServerServiceStatus = "Fail"}
else{$Report_AllServerServiceStatus = "Pass"}
if(($SQLServerPINGStatus.Status -ne "Healthy").Count -gt 0){$Report_SQLServerPINGStatus = "Fail"}
else{$Report_SQLServerPINGStatus = "Pass"}
if(($PoolFileShareAvailability.Status -ne "Healthy").Count -gt 0){$Report_PoolFileShareAvailability = "Fail"}
else{$Report_PoolFileShareAvailability = "Pass"}
if(($ReplicationService.Status -ne "Healthy").Count -gt 0){$Report_ReplicationService = "Fail"}
else{$Report_ReplicationService = "Pass"}
if($ActiveUserCount|Where-Object{($_.Name -notmatch "Teams") -and ($_.Count -gt 1500)}){
    $Report_ActiveUserCount = "Fail"
}
else{
    $Report_ActiveUserCount = "Pass"
}
if([int]($DiskSize | Where-Object{[int]((($_.Available -split '[" "]')[0]) -le 10) -and ($_.Available -ne "")}).Count -gt 0){
    $Report_DiskSize = "Fail"
}
else{$Report_DiskSize = "Pass"}
$Overview = [System.collections.arraylist]@()
$Overview.Clear()
$Properties = [pscustomobject][ordered]@{
    AllServerServiceStatus    = $Report_AllServerServiceStatus
    SQLServerPINGStatus       = $Report_SQLServerPINGStatus
    PoolFileShareAvailability = $Report_PoolFileShareAvailability
    ReplicationService        = $Report_ReplicationService
    ActiveUserCount           = $Report_ActiveUserCount
    DiskSize                  = $Report_DiskSize
}
$Overview.Add($Properties)
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;"><centre>SFB Overall Status Report</span></centre></h3>
"@
$SFBReport = $Overview | ConvertTo-Html -Body $body -Head $head

$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;"><centre>SFB Service Status</span></centre></h3>
"@
$SFBReport += $AllServerServiceStatus| ConvertTo-Html -Body $body -Head $head 
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;">SQL Server PING Status</span></h3>
"@
$SFBReport += $SQLServerPINGStatus| ConvertTo-Html -Body $body -Head $head 
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;">SFB PoolFileShareAvailability</span></h3>
"@
$SFBReport += $PoolFileShareAvailability| ConvertTo-Html -Body $body -Head $head 
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;">SFB Replication Status</span></h3>
"@
$SFBReport += $ReplicationService| ConvertTo-Html -Body $body -Head $head 
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;">SFB Total Active User Count</span></h3>
"@
$SFBReport +=$ActiveUserCount | ConvertTo-Html -Body $body -Head $head 
$body=@"
<h3><span style="color: rgb(235, 107, 86); font-family: Calibri, sans-serif; font-size: 20px;">SFB Disk Size Report</span></h3>
"@
$SFBReport += $DiskSize | ConvertTo-Html -Body $body -Head $head
#$SFBReport | Out-File E:\Software\Scripts\SUMANT.html
if($Overview -match "Fail"){
    $SubjectStatus = "Fail"
}
else{
    $SubjectStatus = "Pass"
}
$SMTPServer = "xxxxxxxxxxxx"
$SMTPPort = "25"
#Add email address of person in to & cc  whom you are sending email (Multiple addresses should be comma seperated)
$to = "User1@email.com,User2@email.com"
#$cc = "User3@email.com"
$subject = "$((Get-Date).GetDateTimeFormats()[0]) - Skype For Business - Daily Health Check - $($SubjectStatus)"
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $SFBReport
$message.to.add($to)
#$message.cc.add($cc)
$message.IsBodyHtml = $True
$message.from = "Automation@email.com"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer,$SMTPPort);
$smtp.send($message)
Write-Host `t -NoNewline
Write-Host "Sending Email...: " -ForegroundColor White -NoNewline
Write-Host "Email Sent" -ForegroundColor Green



---------------------------------- End ---------------------------------- 

Search by Event Logs using Event ID on Servers

 $Servers =
"Server01",
"Server02",
"Server03"

$today = get-date -Hour 0 -Minute 0;

$Servers|ForEach-Object{
Write-Host "Server: $_"
Get-EventLog system -ComputerName $_ -after $today | select -Property * |Where-Object{$_.EventID -eq 7031} | Export-Csv C:\Sumant\SystemEventDetails.csv -NoTypeInformation -Append
}


-------------------------------------- End -------------------------------------- 

Microsoft Teams Report with Member Details

 param(

$Output,
$TotalTeams,
$Mem,
$Created,
$CurrentDate
)

$Admin = "admin@email.com"
Connect-AzureAD
Connect-MicrosoftTeams
Connect-ExchangeOnline -UserPrincipalName $Admin
Connect-IPPSSession -UserPrincipalName $Admin

$TotalTeams= Get-Team

$Output = [System.Collections.ArrayList]@()
$Output.Clear()

Foreach($Teams in $TotalTeams){
    $Mem = Get-TeamUser -GroupId $Teams.GroupId
    $Created = (Get-UnifiedGroup $Teams.GroupId).WhenCreated
    foreach($m in $Mem){
        $Property=[pscustomobject][ordered]@{
            TeamName = $Teams.DisplayName
            Member = $m.name
            Email = $m.user
            Role = $m.role
            CreationDate = $Created
            Description = $Teams.Description
        }
        $Output.add($Property)
    }
}

$CurrentDate = (Get-Date).ToString('MM-dd-yyyy_hh-mm-ss')
$Output | Export-Csv "C:\Output\$CurrentDate _TeamsReport.csv" -NoTypeInformation


----------------------------------- End -----------------------------------


Get the License Assign Date

 # "MCOEV" : Audio Conferencing
# "MCOMEETADV" : Phone System

Connect-MsolService Connect-AzureAD Connect-MicrosoftTeams

#For One User - Get the License AssignDate
$sku ="MCOEV" $user = "user@email.com" $upn = Get-MsolUser -UserPrincipalName $user
$ServicePlanId = Get-AzureADSubscribedSku | ? {$_.SkuPartNumber -like "*$sku*"} | select -expand Serviceplans | select -expand ServicePlanId
$data = (Get-AzureADUser -SearchString $upn.ImmutableId).AssignedPlans |?{$_.ServicePlanId -match $ServicePlanId}

$Property=[pscustomobject][ordered]@{     User = $upn.DisplayName     UserPrincipalName = $upn.UserPrincipalName     License = "AudioConferencing"     AssignDate = $data.AssignedTimestamp     Status = $data.CapabilityStatus     ServicePlanId = $data.ServicePlanId }
$property

#For Entrire Tenant - Get the License AssignDate
$sku = "MCOMEETADV"
$upn = Get-MsolUser -all
#(Get-AzureADGroup -Filter "DisplayName eq 'LG-APP-AZZ-LIC-M365-AUDIOCONF-INTEROP'"| Get-AzureADGroupMember).UserPrincipalName |%{($_ -split '[@]')[0]}
$CurrentDate = ((Get-Date).GetDateTimeFormats())[4]
foreach($u in $upn){
$ServicePlanId = Get-AzureADSubscribedSku | ? {$_.SkuPartNumber -like "*$sku*"} | select -expand Serviceplans | select -expand ServicePlanId
$data = (Get-AzureADUser -SearchString $u.ImmutableId).AssignedPlans |?{$_.ServicePlanId -match $ServicePlanId}

    $Property=[pscustomobject][ordered]@{         User = $u.DisplayName         UserPrincipalName = $u.UserPrincipalName         License = "AudioConferencing"         AssignDate = $data.AssignedTimestamp         Status = $data.CapabilityStatus         ServicePlanId = $data.ServicePlanId     }
    $property | Export-Csv "C:\Sumant\Output\SkypeP4.csv" -NoTypeInformation -Append
    #$property | Export-Csv "C:\Sumant\Output\$CurrentDate _AudioConfReport.csv" -NoTypeInformation -Append
}

 

--------------------------------- End ---------------------------------

Prevent Screen Lock

$WShell = New-Object -Com "Wscript.Shell";
while (1) {$WShell.SendKeys("{SCROLLLOCK}");sleep 60}
 
 
 

Wednesday, 18 December 2024

Export Azure AD Group and Members

 

$Azure_Groups = Get-AzureADGroup -All:$true

$Output = [System.Collections.ArrayList]@()
$Output.Clear()
 
ForEach($Group in $Azure_Groups){
    $GroupObjID = Get-AzureADGroup -Filter "DisplayName eq '$($Group.Name)'"
    $GroupMembers = Get-AzureADGroupMember -ObjectId $GroupObjID.ObjectId
 
    Foreach($Mem in $GroupMembers){
        $Property = [pscustomobject][ordered]@{
            GroupName = $Group.Name
            MemberDisplayName = $Mem.DisplayName
            MemberUserprincipalName = $Mem.UserPrincipalName
            UserType = $Mem.UserType
        }
        $Output.Add($Property)

    }
}

 $Output | Export-Csv C:\AzureAD_Group_Members.csv -NoTypeInformation



--------------------------------- End --------------------------------- 




Certificate Expiry Email Notification

$Output = [System.Collections.ArrayList]@()
$Output.Clear()
$Thumbprint = import-csv "C:\Users\Documents\Thumbprint.txt"
ForEach($t in $Thumbprint){
    $Cert = Get-ChildItem cert:\localmachine\root\* |?{$_.Thumbprint -eq $($t.Thumbprint)} |`
    Select @{n="Subject";e={(($_.Subject -split '[,]')[0]).Replace("CN=","")}},Thumbprint,@{n="NotAfter";e={($_.NotAfter -split '[" "]')[0]}}
    #$Cert
 
    foreach($c in $cert){
        $NumberOfDaysLeft = [math]::Ceiling((([DateTime]$($c.notafter))- (Get-Date)).TotalDays)
        If($NumberOfDaysLeft -lt 60){
            $Property=[pscustomobject][ordered]@{
                Subject    =  $C.Subject
                Thumbprint =  $C.Thumbprint
                NotAfter   =  $C.NotAfter
                DaysLeft   =  $NumberOfDaysLeft
                Status     =  "About To EXPIRE"
            }
           $Output.add($Property)
        }
        else{
            $Property=[pscustomobject][ordered]@{
                Subject    =  $C.Subject
                Thumbprint =  $C.Thumbprint
                NotAfter   =  $C.NotAfter
                DaysLeft   =  $NumberOfDaysLeft
                Status     =  "Pass"
            }
            $Output.add($Property)
        }
    }
}
$Output
$Result = $Output|Where-Object{$_.Status -match "About"}
If($Result.Count -gt 0){
    Write-Host "Kindly Check Email !" -ForegroundColor RED
    $Output
}
else{
    Write-Host "All Good - Nothing to Worry !" -ForegroundColor Green
}


--------------------------------- End --------------------------------- 

EXO Mailbox Permission


$output = [system.collections.arraylist]@()
$output.Clear()
#$upnn = "user@email.com"
$upn = Get-mailbox -recipienttypedetails Sharedmailbox
 
$ErrorActionPreference = "SilentlyContinue"
$upn | foreach{  
    $u = $_.userprincipalname   
 
    [string[]]$FA = (Get-MailboxPermission $u).user #|%{($_ -split '["\\"]')[1]}|%{($_ -split '[,]')}
    [string[]]$SA = (Get-RecipientPermission $u).trustee #|%{($_ -split '["/"]')[2]}#|%{($_ -split '[","]')}
    [string[]]$SOB = (Get-Mailbox $u).GrantSendOnBehalfTo
 
    $Count = ($FA,$Sob,$SA | ForEach-Object {$_ | Measure-Object} | Select-Object Count | Sort-Object count -Descending | Select-Object -First 1).count
    $currentindex = 0
    do
    {
        if($FA[$currentindex]){$CurrentFA = $FA[$currentindex]}
        else{$CurrentFA = " "}
 
        if($SA[$currentindex]){$CurrentSA = $SA[$currentindex]}
        else{$CurrentSA = " "}
 
        if($SOB[$currentindex]){$CurrentSOB = $SOB[$currentindex]}
        else{$CurrentSOB = " "}
 
        $Result = [pscustomobject][ordered] @{
            Type = $_.RecipientTypeDetails
            Mailbox = $u
            FullAccess = $CurrentFA
            SendAs = $CurrentSA
            SendOnBehalf = $CurrentSOB
        }
        $output.Add($Result)
        $Result |Export-Csv "D:\SUMANT\Output\27-Jul-Shared_MailboxPermission.csv" -NoTypeInformation -Append
        $currentindex ++
    }
    until($currentindex -eq $Count )
}
 



--------------------------------- End --------------------------------- 

Analyze Exchange On-prem Databases for Local Move

 
Param(
    $Output=[System.Collections.ArrayList]@(),
    $Report=[System.Collections.ArrayList]@(),
    $MigrationStatus=[System.Collections.ArrayList]@(),
    $Val,
    $Database,
    $i=0,
    $Count=0,
    $CurrentCount=1,
    $Percent=0,
    $MbxCount,
    $DBCount,
    $Users,
    $HtmlReport = $null
)
 
#Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
 
$date = "{0:yyyy_MM_dd-HH_mm}" -f (get-date)
 
#Start-Transcript "C:\Scripts\MBX-Move\$date.txt"
 
#$date = "{0:yyyy_MM_dd-HH_mm}" -f (get-date)
 
#Start-Transcript "C:\Scripts\MBX-Move\$date.txt"
 
Write-Host `n
Write-Host "--------------------------------------------" -ForegroundColor White
Write-Host "| " -ForegroundColor White -NoNewline
Write-Host "Mailbox Database Analysis & Mailbox Move " -ForegroundColor Green -NoNewline
Write-Host "|" -ForegroundColor White 
Write-Host "--------------------------------------------" -ForegroundColor White
Write-Host `n
 
 
########## Removing Failed Mailbox Move
#Write-Host "Step 0: " -ForegroundColor Cyan -NoNewline
##Get-MoveRequest | where-Object{$_.Status -match "Fail"} | Remove-MoveRequest -Confirm:$False
#Write-Host "[Done]" -ForegroundColor Green
 
########## Importing Mailbox Database
Write-Host "Step 1: " -ForegroundColor Cyan -NoNewline
Write-Host "Importing Mailbox Database..." -ForegroundColor White -NoNewline
$Val = (Get-MailboxDatabase -Status| Where-Object{$_.name -match '2019'}|Select Name,@{n='DatabaseSize';e={($_.DatabaseSize).ToGb()}})
Write-Host "[Done]" -ForegroundColor Green
 
########## Filtering Out Journaling and Temp Database
Write-Host "Step 2: " -ForegroundColor Cyan -NoNewline
Write-Host "Filtering Out Journaling and Temp Database..." -ForegroundColor White -NoNewline
$Database = $Val| Where-Object{($_.name -notlike "*TEMP*")}| Sort DatabaseSize -Descending|Select Name,DatabaseSize
Write-Host "[Done]" -ForegroundColor Green
 
########## Fetching Database Size and Mailbox Count
Write-Host "Step 3: " -ForegroundColor Cyan -NoNewline
Write-Host "Fetching Database Size and Mailbox Count..." -ForegroundColor White -NoNewline
#Write-Host "[Please Wait]" -ForegroundColor Green
$Output.Clear()
$DBCount = ($Database|measure).Count
foreach($db in $Database){
    $Percent += (($db|measure).count/ $DBCount)* 100 
    $MbxCount = (Get-mailbox -database $db.name).count
    $Property=[pscustomobject][ordered]@{
        Name=$db.name
        Size=$db.DatabaseSize
        Mailbox=$MbxCount
    }
    $null=$Output.Add($Property)
    Write-Progress -Activity '[Running...]' -Status "[$($CurrentCount) of $($DBCount)] Fetching Details of $($db.Name)" -PercentComplete $Percent
    $CurrentCount++
}
Write-Progress -Activity '[Running...]' -Status "Completed" -Completed
Write-Host "[Done]" -ForegroundColor Green
 
########## Analyzing Database to MoveIn and MoveOut Mailboxes
Write-Host "Step 4: " -ForegroundColor Cyan -NoNewline
Write-Host "Analyzing Database to MoveIn and MoveOut Mailboxes..." -ForegroundColor White -NoNewline
 
$Output=$Output| Select Name,Size,Mailbox,
@{n='MoveIn';e={
        if(($_.Size -lt 150) -and ($_.Mailbox -lt 120)){
            return (120 - $_.Mailbox)
        }
        else{
            return 0
        }
    }
},
@{n='MoveOut';e={
        if(($_.Size -gt 150) -or ($_.Mailbox -gt 120)){
            return ($_.Mailbox - 120)
        }
        else{
            return 0
        }
    }
}
 
$Output|Select Name,Size,Mailbox,MoveIn,MoveOut | Sort-Object MoveIn



--------------------------------- End --------------------------------- 

EXO Migration Diagnostic Report


#Export to XML
Get-MoveRequestStatistics User@email.com  -IncludeReport -Diagnosticinfo -DiagnosticArgument -verbose | Export-CliXml  C:\User.xml
 
#Export to Notepad
Get-MoveRequestStatistics User@email.com  -IncludeReport -Diagnosticinfo -DiagnosticArgument -verbose | out-file c:\temp\user.txt


--------------------------------- End --------------------------------- 

Mailbox Count per DAG (Database Availability Group)

 

$Output = [system.collections.arraylist]@()
$Output.Clear()

$DAG = Get-DatabaseAvailabilityGroup

$DAG |ForEach-Object{

   $DiscoveryMailbox  = $null
   $RoomMailbox     =    $null
   $SharedMailbox     = $null
   $TeamMailbox     =    $null
   $UserMailbox       = $null
   $Total             = $null

   $AllMailbox = Get-Mailbox -ResultSize Unlimited | Where-Object {$_.Database -match $DagName}    
 
   [int]$DiscoveryMailbox  += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Discovery"}).Count)
   [int]$RoomMailbox      += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Room"}).Count)
   [int]$SharedMailbox     += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Shared"}).Count)           
   [int]$TeamMailbox      += [int](($allmailbox|?{$_.RecipientTypeDetails -match "Team"}).Count)          
   [int]$UserMailbox       += [int](($allmailbox|?{$_.RecipientTypeDetails -match "User"}).Count)         
   [int]$Total             += [int]($allmailbox.Count)
 
   $Property=[pscustomobject]@{
       DAG               = "AIB"+ ($DagName.Replace("-","")).ToString()
       DiscoveryMailbox  = $DiscoveryMailbox
       RoomMailbox       = $RoomMailbox   
       SharedMailbox     = $SharedMailbox   
       TeamMailbox       = $TeamMailbox   
       UserMailbox       = $UserMailbox     
       Total             = $Total           
   }
   $Output.Add($Property)
}

 $Output | ft -AutoSize


--------------------------------- End --------------------------------- 

View Shared Mailbox Private Item

 

Get-MailboxFolderPermission SharedMailbox@email.com:\Calendar
 
Add-MailboxFolderPermission SharedMailbox@email.com:\Calendar -User  -AccessRights Editor -SharingPermissionFlags "Delegate,CanViewPrivateItems"
 
Remove-Mailboxfolderpermission Sharedmailbox:\calendar -ResetDelegateUserCollection


--------------------------------- End --------------------------------- 


Send Multiple Attachments Using Powershell

 

# Send Report on Email.
   $SMTPServer = "ServerName"
   $SMTPPort = "25"
   #Add email address of person in to & cc  whom you are sending email (Multiple addresses should be comma seperated)
   $to = "user@email.com"
   $subject = "$((Get-Date).GetDateTimeFormats()[0]) - Report Provisioning EXO E5"
   $message = New-Object System.Net.Mail.MailMessage
   $message.subject = $subject
   $message.body = "Report Provisioning EXO E5"
   $message.to.add($to)
   #$message.cc.add($cc)
   $message.IsBodyHtml = $True
   $message.from = "Report@email.com"
   $attachment = @("C:\Scripts\EXO-E5-LIC-Added.txt","C:\Scripts\$($Date)-RemoteUserMailbox.csv")
   #$attach_log = new-object Net.Mail.Attachment($attachment)

   foreach ($att in $attachment){

      $attach = new-object Net.Mail.Attachment($att)
      $message.Attachments.Add($attach)
   }

   $smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
   $smtp.send($message)
   Write-Host `t -NoNewline
   Write-Host "Sending Email...: " -ForegroundColor White -NoNewline
   Write-Host "Email Sent" -ForegroundColor Green