browolf Posted November 7, 2019 Posted November 7, 2019 It's not having an error but it's coming out wrong. >import-csv "D:\allemail.csv" | foreach {get-mailboxstatistics -identity $_.userprincipalname | select $_.displayname,lastuseractiontime } allemail.csv contains a column of emailaddress and a column of names with the headings userprincipalname and displayname At the moment the heading of the output is like this: Pastoral Triage LastUserActionTime --------------- ------------------ 04/04/2019 12:18:20 22/11/2017 15:57:38 13/11/2018 13:54:15 01/02/2018 2 if I replace $_.displayname with identity I get which is no use. Identity LastUserActionTime -------- ------------------ 943d8acf-a411-429c-99af-4fd77add3111 04/04/2019 12:18:20 a3a85b4c-a751-4ea4-bbd9-584bc7c38111 22/11/2017 15:57:38 It's probably something simple but I haven't found a example that's similar enough to get the answer from.
browolf Posted November 7, 2019 Author Posted November 7, 2019 What do you want the output to be? ideally userprincipalname and lastuseractiontime. so i can find out what emails haven't logged on for ages.
mavhc Posted November 7, 2019 Posted November 7, 2019 https://www.codykonior.com/2013/03/26/powershell-how-to-show-all-of-an-objects-properties-and-values/
browolf Posted November 7, 2019 Author Posted November 7, 2019 https://www.codykonior.com/2013/03/26/powershell-how-to-show-all-of-an-objects-properties-and-values/ That doesn't help because userprincipalname is not in the same object as lastuseractiontime.
Arthur Posted November 7, 2019 Posted November 7, 2019 It's probably something simple but I haven't found a example that's similar enough to get the answer from. Would this do what you need? $Mailboxes = Get-Mailbox -Filter {(RecipientTypeDetails -eq "UserMailbox") -or (RecipientTypeDetails -eq "SharedMailbox")} –ResultSize Unlimited -ErrorAction SilentlyContinue | Sort $Mailboxes | ForEach { Get-MailboxStatistics -Identity $_.UserPrincipalName | Select DisplayName, Last* } | Export-Csv -Path D:\Stats.csv -NoTypeInformation 1
sbrade47 Posted November 7, 2019 Posted November 7, 2019 You don't need to specify the current pipeline object with "$_.Displayname" as you are within a foreach loop running through UserPrincipalNames. Just use "DisplayName, LastUserActionTime" [color=#333333]import-csv "D:\allemail.csv" | foreach {get-mailboxstatistics -identity $_.userprincipalname | select displayname,lastuseractiontime } [/color] 1
browolf Posted November 8, 2019 Author Posted November 8, 2019 You don't need to specify the current pipeline object with "$_.Displayname" as you are within a foreach loop running through UserPrincipalNames. Just use "DisplayName, LastUserActionTime" [color=#333333]import-csv "D:\allemail.csv" | foreach {get-mailboxstatistics -identity $_.userprincipalname | select displayname,lastuseractiontime } [/color] That's it. Thanks!
browolf Posted November 8, 2019 Author Posted November 8, 2019 You don't need to specify the current pipeline object with "$_.Displayname" as you are within a foreach loop running through UserPrincipalNames. Just use "DisplayName, LastUserActionTime" [color=#333333]import-csv "D:\allemail.csv" | foreach {get-mailboxstatistics -identity $_.userprincipalname | select displayname,lastuseractiontime } [/color] on reflection i'd prefer to have userprincipalname,displayname, lastuseractiontime as the output but that doesn't work the same way. I get a blank column if I just do it the same.
sbrade47 Posted November 8, 2019 Posted November 8, 2019 This is a bit dirty but it will do what you need. Normally I would go the PSObject route. import-csv "D:\allemail.csv" | foreach {$UPN = $_.UserPrincipalName; get-mailboxstatistics -identity $UPN | select @{n='UserPrincipalName';e={$UPN}},displayname,lastuseractiontime} 1
browolf Posted November 8, 2019 Author Posted November 8, 2019 This is a bit dirty but it will do what you need. Normally I would go the PSObject route. import-csv "D:\allemail.csv" | foreach {$UPN = $_.UserPrincipalName; get-mailboxstatistics -identity $UPN | select @{n='UserPrincipalName';e={$UPN}},displayname,lastuseractiontime} Thanks. easy when you know how
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now