Last active
June 12, 2020 14:31
-
-
Save TheBigBear/890f9cc7944058c415f03e6221d7c275 to your computer and use it in GitHub Desktop.
howto assign variable from ps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# want to switch from old method using Get-MailboxStatistics cmdlet to using Export-MailboxDiagnosticLogs instaed | |
# as shown at ( https://petri.com/exchange-online-exposes-new-mailbox-activity-data ) | |
#old method using Get-MailboxStatistics cmdlet | |
$UserReport = New-Object PSObject | |
# check for mailbox info | |
foreach ($mbx in $mbxs) { | |
if ($user.UserPrincipalName -eq $mbx.UserPrincipalName) { | |
$mbxstats = Get-MailboxStatistics -Identity $mbx.UserPrincipalName -ErrorAction SilentlyContinue | Select LastUserActionTime,LastLogonTime,SystemMessageSize | |
$LastUserActionTime = $mbxstats.LastUserActionTime | |
$LastLogonTime = $mbxstats.LastLogonTime | |
$SystemMessageSize = $mbxstats.SystemMessageSize | |
#Last User Action Time | |
If($LastUserActionTime -eq $null){ | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Date" -value "No User Action" | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Time" -value "00:00" | |
} | |
Else{ | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Date" -value $LastUserActionTime.ToShortDateString() | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Time" -value $LastUserActionTime.ToShortTimeString() | |
} | |
#Last Logon Time | |
If($LastLogonTime -eq $null){ | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Logon Date" -value "Never Logged In" | |
add-member -inputobject $UserReport -membertype noteproperty -name "Last Logon Time" -value "00:00" | |
} | |
Else{ | |
add-member -inputobject $UserReport -membertype noteproperty -name "Last Logon Date" -value $LastLogonTime.ToShortDateString() | |
add-member -inputobject $UserReport -membertype noteproperty -name "Last Logon Time" -value $LastLogonTime.ToShortTimeString() | |
} | |
# SystemMessageSize | |
If($SystemMessageSize -eq $null){ | |
add-member -inputobject $UserReport -membertype noteproperty -name "Message size" -value "No size" | |
} | |
Else{ | |
add-member -inputobject $UserReport -membertype noteproperty -name "Message size" -value $SystemMessageSize.Value | |
} | |
# new method using Export-MailboxDiagnosticLogs instead | |
$mbxstats = Export-MailboxDiagnosticLogs -Identity $mbx.UserPrincipalName -ExtendedProperties -ErrorAction SilentlyContinue | |
$mbxstats = [xml]($mbxstats.MailboxLog) | |
# how do I now set the $LastUserActionTime $LastLogonTime $SystemMessageSize | |
# the following does not work - (obviously) | |
$LastUserActionTime = $mbxstats.LastUserActionTime | |
$LastLogonTime = $mbxstats.LastLogonTime | |
$SystemMessageSize = $mbxstats.SystemMessageSize | |
# the new data type is System.Xml.XmlElement | |
LastUserActionTime | Get-Member: | |
Name : LastUserActionTime | |
Value : 11/06/2020 09:19:25 | |
LastUserActionTime: System.Xml.XmlElement | |
# I can display all Last.... times using the code in the webpage | |
$mbxstats.Properties.MailboxTable.Property | ? {$_.Name -like "Last*"} | |
# But how do I now assign the 3 variables ( $LastUserActionTime $LastLogonTime $SystemMessageSize ) as in the old method at the top? Will want to split time it into two parts a Date and a Time part again and the Size into a value | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Date" -value $LastUserActionTime.ToShortDateString() | |
add-member -inputobject $UserReport -membertype noteproperty -name "User Action Time" -value $LastUserActionTime.ToShortTimeString() | |
add-member -inputobject $UserReport -membertype noteproperty -name "Message size" -value $SystemMessageSize.Value | |
# what is the correct 'new' syntax to use for setting to the same type of values and tyes? | |
$LastUserActionTime = | |
$LastLogonTime = | |
$SystemMessageSize = | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment