Get-LastLogonStats.ps1<\/a> (4.74 KB)<\/p>","upvoteCount":3,"datePublished":"2015-06-30T11:07:02.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/8","author":{"@type":"Person","name":"brycekatz","url":"https://community.spiceworks.com/u/brycekatz"}},"suggestedAnswer":[{"@type":"Answer","text":"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…<\/p>\n
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!!!<\/p>\n
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).<\/p>\n
Can somebody please help me?<\/p>","upvoteCount":6,"datePublished":"2015-06-29T18:50:39.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/1","author":{"@type":"Person","name":"kyleamidon","url":"https://community.spiceworks.com/u/kyleamidon"}},{"@type":"Answer","text":"
Would you mind posting the code that you have so far, any any error messages that you might be getting.<\/p>\n
Be sure to use the code button < /> on the top bar of the reply window.<\/p>","upvoteCount":0,"datePublished":"2015-06-29T19:18:53.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/2","author":{"@type":"Person","name":"chamele0n","url":"https://community.spiceworks.com/u/chamele0n"}},{"@type":"Answer","text":"
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.<\/p>\n
(Get-Mailbox) | foreach {Get-MailBoxStatistics $_.Identify | Select DisplayName, LastLogonTime} | Export-CSV C:\\Users\\me\\desktop\\LastLogonDate.csv\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2015-06-29T19:26:58.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/3","author":{"@type":"Person","name":"kyleamidon","url":"https://community.spiceworks.com/u/kyleamidon"}},{"@type":"Answer","text":"Mind you…that’s just one part.<\/p>","upvoteCount":0,"datePublished":"2015-06-29T19:28:01.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/4","author":{"@type":"Person","name":"kyleamidon","url":"https://community.spiceworks.com/u/kyleamidon"}},{"@type":"Answer","text":"
I’m pretty sure I have scripts for both of those.<\/p>\n
I’ll check when I’m back in the office tomorrow.<\/p>","upvoteCount":2,"datePublished":"2015-06-29T19:42:41.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/5","author":{"@type":"Person","name":"brycekatz","url":"https://community.spiceworks.com/u/brycekatz"}},{"@type":"Answer","text":"
Get-ADComputer -Filter * -Properties * | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\\Temp\\ComputerLastLogonDate.txt\n<\/code><\/pre>\nGet-ADComputer -Filter * -Properties * | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\\Temp\\ComputerLastLogonDate.txt\n<\/code><\/pre>\nNot 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.<\/p>","upvoteCount":0,"datePublished":"2015-06-29T20:31:04.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/6","author":{"@type":"Person","name":"kyleamidon","url":"https://community.spiceworks.com/u/kyleamidon"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Bryce Katz:<\/div>\n
\nI’m pretty sure I have scripts for both of those.<\/p>\n
I’ll check when I’m back in the office tomorrow.<\/p>\n<\/blockquote>\n<\/aside>\n
I’m EXCITED!!! Can’t wait to hear back from you.<\/p>\n
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<\/p>","upvoteCount":1,"datePublished":"2015-06-29T20:33:13.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/7","author":{"@type":"Person","name":"kyleamidon","url":"https://community.spiceworks.com/u/kyleamidon"}},{"@type":"Answer","text":"
“AND inactive computers from the last 30 days” - That at least is easy with the AD cmdlets.<\/p>\n
Search-ADAccount -ComputersOnly -AccountInactive -TimeSpan 30\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2015-06-30T11:20:05.000Z","url":"https://community.spiceworks.com/t/death-by-powershell/415766/9","author":{"@type":"Person","name":"craigduff","url":"https://community.spiceworks.com/u/craigduff"}},{"@type":"Answer","text":"