Skip to content

Instantly share code, notes, and snippets.

@Tiberriver256
Created January 27, 2016 03:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiberriver256/4d6a43fd7254785aa8fd to your computer and use it in GitHub Desktop.
Save Tiberriver256/4d6a43fd7254785aa8fd to your computer and use it in GitHub Desktop.
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
Connect-MsolService -credential $UserCredential
$ReportPath = "C:\filename"+ (Get-Date -UFormat %D).Replace("/",".") +".csv"
$Report = @()
Write-Host "Getting Users..."
$TimeToGetUsers = Measure-Command -Expression { $AllUsers = get-msoluser -All }
Write-Host "Getting mailboxes..."
$TimeToGetMailboxes = Measure-Command -Expression { $Mailboxes = Get-Mailbox -ResultSize Unlimited }
$MailboxesHash = @{}
foreach ($Mailbox in $Mailboxes)
{
$MailboxesHash.Add($Mailbox.UserPrincipalName,$Mailbox)
}
$i = 0
foreach ($User in $AllUsers)
{
Write-Progress -Activity "Getting information..." -Status "$($User.UserPrincipalName)" -PercentComplete ( ($i/$AllUsers.Count) * 100 )
$UserPrincipalName = $User.UserPrincipalName
$Mbx = $MailboxesHash[$UserPrincipalName]
$Information = New-Object -TypeName PSObject -Property @{
'UserPrincipalName' = $User.UserPrincipalName
'Alias' = $mbx.Alias
'IsLicensed' = $User.IsLicensed
'Licenses' = $User.Licenses.AccountSkuId
'AccessType' = $mbx.Alias
'RetentionPolicy' = $mbx.retentionpolicy
'ExchangeUserAccountControl' = $mbx.exchangeuseraccountcontrol
'AccountDisabled' = $mbx.accountdisabled
'LitigationHoldOwner' = $mbx.LitigationHoldOwner
'RemoteRecipientType' = $mbx.remoterecipienttype
}
$Report += $Information
$i++
}
$Report | Export-Csv -Path $ReportPath -Encoding ASCII
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment