I haven’t written and PowerShell script in a while…<\/p>\n
I want to write a ps1 script that will generate a CSV with the following:<\/p>\n
All mail users<\/p>\n
Mail users’ job titles<\/p>\n
The last time each mail user logged in<\/p>\n
This is for Office 365.<\/p>\n
(I was able to generate two individual CSV files and combine them, but it was too time consuming!)<\/p>\n
I thought I would use Get-MailBox and Get-MailboxStatistics to get the display name and last logon time, and I can use Get-AzureADUser to get the job title.<\/p>\n
If I used Get-MailBox and Get-MailboxStatistics together to output to a CSV, then I could use the CSV file to get the usernames for Get-AzureADUser, and then output the display name, job title, and last logon to a new CSV, and then delete the original CSV.<\/p>\n
Where I need help is with getting variables from the first CSV and with the looping the script.<\/p>\n
Below is some ps1 and pseudocode<\/p>\n
mkdir c:\\scripts\nGet-MailBox -ResultSize unlimited | Get-MailboxStatistics | Select DisplayName, LastLogonTime | Export-Csv c:\\scripts\\last_logon_TEMP.csv\n\n#pseudo code\n# $DisplayName = column A from c:\\scripts\\last_logon_TEMP.csv\n# $LastLogon = column B from c:\\scripts\\last_logon_TEMP.csv\n# for \n# each DisplayName, \n# $JobTitle = Get-AzureADUser $DisplayName | Select JobTitle >> $DisplayName,$JobTitle,$LastLogon >> c:\\scripts\\name_title_lastlogon.csv\n# end\n\ndel c:\\scripts\\last_logon_TEMP.csv\n<\/code><\/pre>\n