Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function Connect-EXOnline{
- param (
- [string]$Credential
- )
- $credentials = Get-Credential -Credential $Credential
- Write-Output "Getting the Exchange Online cmdlets"
- $Session = New-PSSession -ConnectionUri https://outlook.office365.com/powershell-liveid/ `
- -ConfigurationName Microsoft.Exchange -Credential $credentials `
- -Authentication Basic -AllowRedirection
- Import-PSSession $Session
- }
- Function disconnect-EXOnline {
- $session = Get-PSSession
- foreach ($id in $session) {
- if ($id.ConfigurationName -eq 'Microsoft.Exchange') {
- Remove-PSSession $session
- }
- }
- }
- Function Get-DisabledButLicensedMailboxes {
- param (
- [string]$CSVFileLocation
- )
- $mailboxes = Get-Mailbox -ResultSize unlimited | Where-Object AccountDisabled -eq $True | Select-Object -Property Name,Alias,PrimarySmtpAddress,UserPrincipalName,AccountDisabled,Database,ProhibitSendQuota
- [array]$DisabledMailboxes = @()
- foreach ($mailbox in $mailboxes){
- $LicenseInfo = Get-MsolUser -UserPrincipalName $mailbox.UserPrincipalName -ErrorAction SilentlyContinue | select-object DisplayName,Licenses,IsLicensed
- if ($LicenseInfo.IsLicensed -eq $True) {
- $AccountSkuID = ($LicenseInfo.licenses).AccountSkuID
- if (($AccountSkuID -like "*STANDARD*") -or ($AccountSkuID -like "*ENTERPRISE*")){
- $stats = Get-MailboxStatistics $mailbox.UserPrincipalName
- $DisabledButLicensed = New-Object -TypeName psobject
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name Name -Value $mailbox.Name
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name Alias -Value $mailbox.Alias
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name PrimarySmtpAddress -Value $mailbox.PrimarySmtpAddress
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $mailbox.UserPrincipalName
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name AccountDisabled -Value $mailbox.AccountDisabled
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name Database -Value $mailbox.Database
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name ProhibitSendQuota -Value $mailbox.ProhibitSendQuota
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name AccountSkuID -Value $AccountSkuID
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name IsLicensed -Value $LicenseInfo.IsLicensed
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name MailboxTypeDetail -Value $stats.MailboxTypeDetail
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name TotalItemSize -Value $stats.TotalItemSize
- $DisabledButLicensed | Add-Member -MemberType NoteProperty -Name LastUserActionTime -Value $stats.LastUserActionTime
- $DisabledMailboxes += $DisabledButLicensed
- }
- }
- }
- $DisabledMailboxes | Export-Csv $CSVFileLocation -NoTypeInformation
- $DisabledMailboxes | Out-GridView
- }
- #Change these items to fit your domain and email address.
- $emailAddress = "address@domain.ca"
- $csv = "C:\bin\Company-disabled-Mailboxes.csv"
- Connect-EXOnline -Credential $emailAddress
- Connect-MsolService
- Get-DisabledButLicensedMailboxes -CSVFileLocation $csv
- Disconnect-EXOnline
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement