nav2567
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.
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.
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
PS C:\Windows\system32> Get-Mailbox -Identity "gmiller" | Select-Object DisplayName, UserPrincipalName, MailboxPlan, ServerName, AccountDisabled
DisplayName : Gregory A. Miller
UserPrincipalName : gmiller@geek............
MailboxPlan : ExchangeOnlineEnterprise-.
ServerName : mwhpr.....814
AccountDisabled : False
post your current script so that we can take a look at the syntax
this makes troubleshooting alot easier
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.Validi tyPeriod.T oString()
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";exp ression={[ math]::Rou nd(($_.Tot alItemSize .ToString( ).Split("( ")[1].Spli t(" ")[0].Replace(",","")/1MB) ,2)}}
$TotalItemSize = $TotalItemSize.TotalItemSi ze
$RecipientTypeDetails = $mailbox.RecipientTypeDeta ils
$MSOLUSER = Get-MsolUser -UserPrincipalName $UserPrincipalName
if ($UserDomain -eq $MSOLDomain.name) {$DaysToExpiry = $MSOLUSER | select @{Name="DaysToExpiry"; Expression={(New-TimeSpan -start (get-date) -end ($_.LastPasswordChangeTime stamp + $MSOLPasswordPolicy)).Days }}; $DaysToExpiry = $DaysToExpiry.DaysToExpiry }
$Information = $MSOLUSER | select FirstName,LastName,@{Name= 'DisplayNa me'; Expression={[String]::join (";", $DisplayName)}},@{Name='Al ias'; Expression={[String]::join (";", $Alias)}},@{Name='UserPrin cipalName' ; Expression={[String]::join (";", $UserPrincipalName)}},Offi ce,Departm ent,@{Name ='TotalIte mSize (MB)'; Expression={[String]::join (";", $TotalItemSize)}},@{Name=' LastLogonT ime'; Expression={[String]::join (";", $LastLogonTime)}},LastPass wordChange Timestamp, @{Name="Pa sswordExpi rationIn (Days)"; Expression={[String]::join (";", $DaysToExpiry)}},@{Name='R ecipientTy peDetails' ; Expression={[String]::join (";", $RecipientTypeDetails)}},i slicensed, @{Name="Li censes"; Expression ={$_.Licenses.AccountSkuId }}
$Report = $Report+$Information
}
$Report | export-csv c:\temp\MyReport.csv
Get-PSSession | Remove-PSSession
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.Validi
foreach ($mailbox in $Mailboxes) {
$DaysToExpiry = @()
$DisplayName = $mailbox.DisplayName
$UserPrincipalName = $mailbox.UserPrincipalName
$UserDomain = $UserPrincipalName.Split('
$Alias = $mailbox.alias
$MailboxStat = Get-MailboxStatistics $UserPrincipalName
$LastLogonTime = $MailboxStat.LastLogonTime
$TotalItemSize = $MailboxStat | select @{name="TotalItemSize";exp
$TotalItemSize = $TotalItemSize.TotalItemSi
$RecipientTypeDetails = $mailbox.RecipientTypeDeta
$MSOLUSER = Get-MsolUser -UserPrincipalName $UserPrincipalName
if ($UserDomain -eq $MSOLDomain.name) {$DaysToExpiry = $MSOLUSER | select @{Name="DaysToExpiry"; Expression={(New-TimeSpan -start (get-date) -end ($_.LastPasswordChangeTime
$Information = $MSOLUSER | select FirstName,LastName,@{Name=
$Report = $Report+$Information
}
$Report | export-csv c:\temp\MyReport.csv
Get-PSSession | Remove-PSSession
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.