I need help everyone, I’ve been trying for days to figure out how to write a script to show me inactive users from our Office 365 AND inactive computers from the last 30 days, exporting the results, then emailing them to our support email…

I have the email part down, I have the Inactive users and computers, but for the life of me I can’t figure out where to stick New-TimeSpan!!!

Another thing, I have 50+ tickets and they just keep piling up so I don’t have a lot of time to write this thing out (put the scraps together).

Can somebody please help me?

6 Spice ups

Would you mind posting the code that you have so far, any any error messages that you might be getting.

Be sure to use the code button < /> on the top bar of the reply window.

um…well…sure. But my main issue is that I don’t have a solution for New-TimeSpan. I need to utilize that cmdlet to get only users whom haven’t logged on Office 365 in over 30 days.

(Get-Mailbox) | foreach {Get-MailBoxStatistics $_.Identify | Select DisplayName, LastLogonTime} | Export-CSV C:\Users\me\desktop\LastLogonDate.csv

Mind you…that’s just one part.

I’m pretty sure I have scripts for both of those.

I’ll check when I’m back in the office tomorrow.

2 Spice ups
Get-ADComputer -Filter * -Properties *  | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\Temp\ComputerLastLogonDate.txt
Get-ADComputer -Filter * -Properties *  | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\Temp\ComputerLastLogonDate.txt

Not sure why it’s posting twice…but w/e. Anyway, then this script for giving me the last logon date of computers if they haven’t been logged onto for over 30 days.

I’m EXCITED!!! Can’t wait to hear back from you.

Yeah I’ve been desperately learning Powershell since my boss wants us to use it for Automation at my new job (which I frickin’ love!!!) It’s exciting, Powershell is a godsend

1 Spice up

LastLogon stats for O365, written by Alan Byrne, is attached. Read the comments in the script. Works as described.

I didn’t actually save the bit about computer account age, but it is the Best Answer in this topic:

http://community.spiceworks.com/topic/1026337-convert-whencreated-time-get-adcomputer

Get-LastLogonStats.ps1 (4.74 KB)

3 Spice ups

“AND inactive computers from the last 30 days” - That at least is easy with the AD cmdlets.

Search-ADAccount -ComputersOnly -AccountInactive -TimeSpan 30
3 Spice ups

I have that same script, works incredibly! Though where would I put that I specifically want users whom haven’t logged on in over 30 days?