Link to home
Start Free TrialLog in
Avatar of nav2567
nav2567Flag for United States of America

asked on

Office 365 user report

Hi,

I have been trying to put together a powerscript command and return the below information for our Office 365 users and it is not working.  

Firstname
Lastname
UPN
Last access date of the mailbox.  
Size of the mailbox
License type the mailbox is using.  
License location (US/France/...)
Sign-in status (whether the account is blocked or allowed)

Please advise.

Thanks.
Avatar of Gregory Miller
Gregory Miller
Flag of United States of America image

Can you post what you have and the error it gives? Please remove any embedded credentials or domain names, etc before posting.
Is this basically what you are wanting? Some of the info you want resides in MSOL and some resides in Azure

PS C:\Windows\system32> Get-Mailbox -Identity "gmiller" | Select-Object DisplayName, UserPrincipalName, MailboxPlan, ServerName, AccountDisabled


DisplayName       : Gregory A. Miller
UserPrincipalName : gmiller@geek............
MailboxPlan       : ExchangeOnlineEnterprise-...................................fcf6
ServerName        : mwhpr.....814
AccountDisabled   : False
post your current script so that we can take a look at the syntax

this makes troubleshooting alot easier
Hi,  Good morning !

Run the below code in Powershell

Important :- Before running the script below, please edit the second last line as it has my computer's local path, if you don't have that directory in your system, it will give you an error.

This code will give you the desired output with details.

Hope it helps !

Regards
Anurag ★ !


$Credentials = Get-Credential
Import-Module msonline
Connect-MsolService -Credential $Credentials
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $Credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
$Report=@()
$Mailboxes = Get-Mailbox -ResultSize Unlimited | where {$_.RecipientTypeDetails -ne "DiscoveryMailbox"}
$MSOLDomain = Get-MsolDomain | where {$_.Authentication -eq "Managed" -and $_.IsDefault -eq "True"}
$MSOLPasswordPolicy = Get-MsolPasswordPolicy -DomainName $MSOLDomain.name
$MSOLPasswordPolicy = $MSOLPasswordPolicy.ValidityPeriod.ToString()
foreach ($mailbox in $Mailboxes) {
$DaysToExpiry = @()
$DisplayName = $mailbox.DisplayName
$UserPrincipalName  = $mailbox.UserPrincipalName
$UserDomain = $UserPrincipalName.Split('@')[1]
$Alias = $mailbox.alias
$MailboxStat = Get-MailboxStatistics $UserPrincipalName
$LastLogonTime = $MailboxStat.LastLogonTime
$TotalItemSize = $MailboxStat | select @{name="TotalItemSize";expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),2)}}
$TotalItemSize = $TotalItemSize.TotalItemSize
$RecipientTypeDetails = $mailbox.RecipientTypeDetails
$MSOLUSER = Get-MsolUser -UserPrincipalName $UserPrincipalName
if ($UserDomain -eq $MSOLDomain.name) {$DaysToExpiry = $MSOLUSER |  select @{Name="DaysToExpiry"; Expression={(New-TimeSpan -start (get-date) -end ($_.LastPasswordChangeTimestamp + $MSOLPasswordPolicy)).Days}}; $DaysToExpiry = $DaysToExpiry.DaysToExpiry}
$Information = $MSOLUSER | select FirstName,LastName,@{Name='DisplayName'; Expression={[String]::join(";", $DisplayName)}},@{Name='Alias'; Expression={[String]::join(";", $Alias)}},@{Name='UserPrincipalName'; Expression={[String]::join(";", $UserPrincipalName)}},Office,Department,@{Name='TotalItemSize (MB)'; Expression={[String]::join(";", $TotalItemSize)}},@{Name='LastLogonTime'; Expression={[String]::join(";", $LastLogonTime)}},LastPasswordChangeTimestamp,@{Name="PasswordExpirationIn (Days)"; Expression={[String]::join(";", $DaysToExpiry)}},@{Name='RecipientTypeDetails'; Expression={[String]::join(";", $RecipientTypeDetails)}},islicensed,@{Name="Licenses"; Expression ={$_.Licenses.AccountSkuId}}
$Report = $Report+$Information
}
$Report | export-csv c:\temp\MyReport.csv        
Get-PSSession | Remove-PSSession
Avatar of nav2567

ASKER

Anurag,

I do not see the second line.  Can  you explain?

I am trying your script and I do not see any report is returned.  It is just sitting there.  

Angelo,

I am trying Get-MsolUser -All | ?{$_.islicensed -eq $true} | select displayname, userprincipalname -ExpandProperty licenses | select displayname, Userprincipalname, AccountSkuid | Export-Csv

I need to add Firstname, lastname, last access date of the mailbox, mailbox/license location , and whether the account is blocked or not.
ASKER CERTIFIED SOLUTION
Avatar of Anurag Gautam
Anurag Gautam
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial