We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

tomnek • 8 months ago

How does one include the DEVICE upon which the user has logged in?? This is useful for knowing who uses which device. It has to go into the table as either Device Name or Serial Number, preferably both. Thank you, : ) tom

Kavya • 8 months ago

Hi Tom,
To include device details, you would need to use the audit log, which requires to interact with the Exchange Online PowerShell module.
However, another approach could be considering the use of AdminDroid's Microsoft 365 reporting tool. Feel free to explore their demo via the link provided for further insights.
https://demo.admindroid.com/#/1/11/reports/20300/1/20?easyFilter=%7B%22isInteractive%22%3A1%7D

Kabir • 1 year ago

Hi
Q1. I am getting the below error but
.\UserLastActivityTimeReport.ps1
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following error message : Access is denied. For more information, see the about_Remote_Troubleshooting Help topic.
At \Desktop\Office365UserLastActivityTime\UserLastActivityTimeReport.ps1:214 char:14
+ ... $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conn ...

where I am running as Global admin account. Please let me know.

2. how can I get user manager displayname for each user?

Otherwise, this is great.

Thank you

KathyCooper • 1 year ago

Hi Kabir,
Usually, this error is thrown when you try to create session using MFA enabled account. Is your global admin account MFA enabled? If so, please run the script with -MFA param as we described in our blog.

To get manager name, you need to import AzureAD PowerShell module and use the Get-AzureADUserManager cmdlet.

Kabir • 1 year ago

1. I am not using MFA enabled account. Can I use connect-exchagneonline instead of this line? OR what is your recommendation?
2. I know this Get-AzureADUserManager cmdlet but like to know where and how do I use it? I believe that I also need to make AzureAD connection as well to get that comlet working. Please let me know

Appreciate your help as always you do best script.

KathyCooper • 1 year ago

Hi Kabir,
I have updated the script to use the EXO V2 module, i.e., Connect-ExchangeOnline. You can download the updated version and let us know if you are still facing any issues.

Regarding the manager attribute, You need to create an AzureAD PowerShell session using the Connect-AzureAD cmdlet. Then run the Get-AzureADUserManager cmdlet. To get a user's manager, you can use the below syntax:
(Get-AzureADUserManager -ObjectId <userupn>).userprincipalname

Kabir • 1 year ago

Great!!! it is working flawlessly.
Awesome Script.
Thank you very much!!!!

KathyCooper • 1 year ago

Thank you for the update, kabir.

Farshad • 1 year ago

Hi Kathy looks like the script wont work on the new MFA EXO v3, can you help please?
Thanks!

KathyCooper • 1 year ago

Hi Farshad,
The script appears to be working properly with the EXO V3 module. Could you please provide more information on how you ran the script and any errors you encountered?

Jason Wingert • 1 month ago

Hello,

I greatly appreciate this script and its very helpful. I'm running into a problem where its not grabbing all of the users from Office365. I compared an export from the M365 Active Users area and I have 133 users but your script only sees115 of them. I did a quick comparison and and it missed a very standard account of customerservice@domain.com with nothing special about the account. Any idea why this might be happening?

Edit: I should add that I didn't use any special syntax. I ran powershell as an admin w/ -ep bypass. No extra switches. Just Simply ./UserLastActivityTimeReport.ps1

Kavya • 1 month ago

Hi Jason Wingert,
Thank you for your kind words. Regarding your issue, the script utilizes the 'LastUserActionTime' attribute available in the Get-MailboxStatistics cmdlet. This means it will only retrieve mailboxes and won't include user accounts without Exchange Online licenses. It's possible that this discrepancy in user count is due to the presence of user accounts without Exchange Online licenses.

To retrieve last sign-in times for all users, including those without Exchange Online licenses, you can use Microsoft Graph. We have a script available for this purpose; You can download the script from 'Find inactive users in Microsoft 365'.

Mido • 5 months ago

Hello. This is agreat script btw. I have a quick question about an issue I am seeing as to where I am running the script but it is only seeing 12 of the 1000 users we have. Is there something I am doing wrong?

Kavya • 5 months ago

Hi Mido,
Did you run the script with any filtering parameters? Did the script execution complete and prompt for opening the output file, or did you encounter any errors? If you encountered any error, please share the screenshot. It'd be helpful to identify the cause of the error.

Mido • 5 months ago

Hey Kavya,
Thanks for getting back to me so fast. I am runnning the Export Office 365 Mailboxes to CSV parameter. I don't really see any erros per say other then it only detecting a max of 12 accounts. I also get the prompt to open the file and it has the correct info in there. I was just confused about the amount of users that came back becuase it should be about 1000 of them. So I wasn't sure if I was running it correctly. I am using a global admin account to run this so it should have enough permission to get this info.

https://uploads.disquscdn.c...

Mido • 5 months ago

I have a quick question. This is only getting that info from mailboxes correct. This might be the issue then. I didn't put 2 and 2 together lol. Is it possible that I can edit the script to detect lastlongintime for O365 online users instead of mailboxes.

Kavya • 5 months ago

Hi Mido,
Thanks for your update. LastLogonTime attribute available in 'Get-MailboxStatistics' cmdlet which is available only for mailboxes.

To view the last sign in time for all Office 365 users, you can use the MS Graph and the script is here: https://o365reports.com/2023/06/21/microsoft-365-inactive-user-report-ms-graph-powershell/
The script will show the last interactive sign-in time, non-interactive sign-in time, inactive days, etc., for all users. I hope this one will help you.

Mido • 5 months ago

Hey Kavya,

Thanks for this. I will definetly give this a try and keep you updated.

Mido • 5 months ago

Hey Kavya,

So I tried the other script you sent me and I ran into an issue. I am using the free version so I don't have a license tied to my instance. Is this only possible if I have a license.
https://uploads.disquscdn.c...

Eslam Shaban • 6 months ago

How can i add title, department and office attributes to the exported csv report?

Kavya • 6 months ago

Hi Eslam Shaban,
To include the title, department, and office attributes, you need to make a slight modification to the code. For your reference, I've attached a screenshot that highlights the specific code and line that should be adjusted. After making the modification, execute the script and let us know how it works.
https://uploads.disquscdn.c...

Scriptuser • 7 months ago

The script worked perfectly for many months and now it pauses on this
This V3 EXO PowerShell module contains new REST API backed Exchange Online cmdlets which doesn't require WinRM for Client-Server communication. You can now run these cmdlets after turning off WinRM Basic Auth in your client machin
e thus making it more secure.

Unlike the EXO* prefixed cmdlets, the cmdlets in this module support full functional parity with the RPS (V1) cmdlets.

V3 cmdlets in the downloaded module are resilient to transient failures, handling retries and throttling errors inherently.

REST backed EOP and SCC cmdlets are also available in the V3 module. Similar to EXO, the cmdlets can be run without WinRM basic auth enabled.

For more information check https://aka.ms/exov3-module

Any help would be much apprreciated.

Kavya • 7 months ago

Hi,
This is not an error but the default description for the EXO V3 module, which is displayed when the Exchange Online PowerShell connection is established. The script will begin processing users once the connection is established. If you encounter any issues or need further assistance, please share a screenshot to help us better understand the problem and provide a solution.

Scriptuser • 7 months ago

Thank you for the reply, the issue is when on V3 the script just puts this message up and does not connect to exchange. I have left it for hours.

Kavya • 7 months ago

Hi,
If you use MFA and don't pass the credentials as parameters, the script will prompt you to enter credentials twice. The first prompt is to connect to Exchange Online (to retrieve last activity time), and the second is to connect to Azure AD (to retrieve assigned licenses and roles). I believe the script may have waited for you to provide credentials to connect to Azure AD. Once the session is created successfully, the script will proceed to process users.

Franz • 8 months ago

I get this when using a csv file:
Execute-Command : Cannot process argument transformation on parameter 'ParameterBasedRoutingHintParameterValue'. Cannot convert value to type System.String.
At C:\Users\xxxx\AppData\Local\Temp\5\tmpEXO_q1ulirvh.upe\tmpEXO_q1ulirvh.upe.psm1:36905 char:202
+ ... outingHint -ParameterBasedRoutingHintParameterValue $Identity -UsePar ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Execute-Command], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Execute-Command

Franz • 8 months ago

Hello - I've not been able to get past this even though I'm using a import csv with just over 1200 mailboxes.
($Mailboxes=Import-Csv XXXXXXX.csv -Header "XXXXX_ACCT").count
1227
Error:
WARNING: There are more results available than are currently displayed. To view them, increase the value for the ResultSize parameter.
Execute-Command : Cannot process argument transformation on parameter 'ParameterBasedRoutingHintParameterValue'. Cannot convert value to type System.String.
At C:\Users\fkingXXXXX\AppData\Local\Temp\16\tmpEXO_mfogo5ln.bpk\tmpEXO_mfogo5ln.bpk.psm1:36901 char:202
+ ... outingHint -ParameterBasedRoutingHintParameterValue $Identity -UsePar ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Execute-Command], ParameterBindingArgumentTransformationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Execute-Command

Thank you

Franz • 8 months ago

I've gotten past this error - I had to add -resultsize unlimited at line 256 - $MBDetails=Get-Mailbox -Identity $item.MBIdentity. The message I'm receiving does seem to mean that all mailboxes are being polled.

tomnek • 8 months ago

HOW does one include the DEVICE name or serial number upon which the user logged in??

Umar Farooq • 11 months ago

Hello Kathy,

Switch -MBNamesFile C:/MBIdentity.txt is not working for me

Getting error: Import-Csv : Could not find file 'C:\M.txt'.
At C:\Users\UmarFarooq\Desktop\OfficeLastActivity\UserLastActivityTimeReport.ps1:227 char:14
+ $Mailboxes=Import-Csv -Header "MBIdentity" $MBNamesFile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Import-Csv], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportCsvCommand

I have added 72 emails in the .txt file.

KathyCooper • 11 months ago

Hi Umar Farooq,
Based on the error message "Couldn't find the file C:\M.text," please ensure that the file is available in the specified location (C:\M.text).
If the file is not present or if the file path is incorrect, you will encounter this error.

Ric Turner • 1 year ago

Hello,
Upon running the script we found it was extremely slow, processing one mailbox every 3-5 seconds. We have approximately 50k mailboxes in the tenant, and our estimate is about 5-6 days minimum to complete the script, if it completes without timing out. Is there anything we can do to speed things up?

Thanks in advance.

KathyCooper • 1 year ago

Hi Ric Turner,
The script's processing time can be affected by a number of factors, such as network latency, server performance, and the number of mailboxes being processed. Here are a few potential strategies you could consider to speed up the script's execution:

1.If you only need to collect data for a subset of mailboxes, consider using the import CSV option to reduce the overall processing time. This allows you to import a list of mailboxes from a CSV file and use it to filter which mailboxes the script should process.

2.You can also filter the mailboxes by using the -RecipientTypeDetails parameter to process specific mailbox types.

3.Slow network performance can significantly impact the script's execution time. Ensure that your network connection is stable and fast.

4.If you're interested in a third-party tool, try AdminDroid, which offers a 15-day free trial and comes with over 1600 pre-built reports.

Ric Turner • 1 year ago

Hi Kathy,

Thanks for the reply. I actually did one small edit to the script that made a *huge* difference - I changed Get-Mailbox to Get-EXOMailbox, and I could tell immediately the difference in speed. It was much faster, processing one user per second as opposed to one user every 3-5 seconds or longer. It completed the script successfully in approximately 20 hours, and it returned results for just short of 49,000 users.

KathyCooper • 1 year ago

Thank you for the update, Ric Turner. We are glad to hear that you resolved the issue.

Hi, This is great! the script is running perfectly! I added Departments based on a question below and it works, however, I also want to add Employee IDs. I added $EmployeeId=$UserInfo.EmployeeId
to the script but it doesn't work, any suggestions? Thanks

KathyCooper • 1 year ago

Hi,
The 'Employee ID' attribute is not supported by Microsoft's Get-MSolUser cmdlet. You need to use Get-AzureADUser, which requires Azure AD PowerShell module.
For example,
Get-AzureADuser -ObjectId <id> | Select-Object -ExpandProperty ExtensionProperty
The above code will show the employee id of the user.

Thanks Kathy, any way I can incorporate that into this script?

KathyCooper • 1 year ago

Yes, After connecting to Azure AD module, you can use the given code to retrieve Employee Id. And then you can store it in a $Output variable to export to the CSV file.

thanks, so I'm not sure if I'm going in the right direction or not, but I added this command under "Connecting Azure AD...":

Get-AzureADuser -All: $true | Select-Object -ExpandProperty ExtensionProperty

and added EID to the Output file:

$Output | Select-Object $Result=@{'UserPrincipalName'=$upn;'DisplayName'=$DisplayName;'Department'=$Department;'EID'=$EmployeeId;'LastUserActionTime'=$LastActionTime;'LastActionTimeUpdatedOn'=$LastActionTimeUpdatedOn;'CreationTime'=$CreationTime;'InactiveDays'=$InactiveDaysOfUser;'MailboxType'=$MBType; 'AssignedLicenses'=$AssignedLicense;'Roles'=$RolesAssigned}

now I assume I need to add $EmployeeId, what should it be?
$EmployeeId=

KathyCooper • 1 year ago

Hi,
You need to install Azure AD module and connect to Azure AD PowerShell to retrieve employee id. I have marked the code to be added along with the line number. Please refer the below screenshot.
https://uploads.disquscdn.c...

I hope this will resolve your requirement. Let us know how it worked.

Perfect! it works! thank you so much!
one small change I made was to replace the EmpId command, and it worked.
https://uploads.disquscdn.c...

KathyCooper • 1 year ago

Thank you for the update. We are glad to help you.

Wilco van der Spek • 1 year ago

i receive an error that basic authentication is turned off, how can we make this script work?

Vlado • 1 year ago

Hello,
The number of Users according to the standard report from Azure admin panel is more than 10,000, but the script stops somewhere at 6890 without errors and additional messages. What could be a reason?

execution of PS
> (Get-AzureADUser -all $true | Where {$_.DirSyncEnabled -eq $true}).Count
8251

what should I missed or what additional should be considered to find last user activity date time within o365 services (Teams, Exchange online and other apps and services)

KathyCooper • 1 year ago

Hi Vlado,
The script retrieves the last activity time for all the mailboxes using theGet-MailboxStatistics cmdlet. I believe your environment has 6890 mailboxes. You can check the total mailboxes count using the Get-Mailbox cmdlet. If there is any count mismatch, let us know.

Dan • 1 year ago

Hey I'm trying to run the script which works perfectly but I also need to capture more information
- Department
- Account Status
- Directory Synced
Is it possible to get this added, when I try adding the sections the script just doesn't run.

KathyCooper • 1 year ago

Hi Dan,
To capture the required information, you need to retrieve those attributes from the respective cmdlets. You can refer to the screenshot below to know the attribute/code placement in the script. Let me know how it works.
https://uploads.disquscdn.c...

Dan • 1 year ago

Are you using a newer script? I don't seem to have the line 239-267, are you able to send me a copy of your script?

KathyCooper • 1 year ago

Hi Dan,
We have updated the script few days back. If you are using older version, you can download the newer version from the link given in the blog.