Created
January 27, 2016 03:45
-
-
Save Tiberriver256/4d6a43fd7254785aa8fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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