Powershell/script issue

7 views
Skip to first unread message

Mayo, Bill

unread,
May 18, 2021, 10:28:40 AM5/18/21
to ntexc...@googlegroups.com

I have a script that gets mailbox attributes and puts it in a custom object for account auditing purposes. The script runs fine from an Exchange server. I am trying to adapt it to be run from a different location, where Exchange isn’t installed, using an imported session. Generally speaking, I have had no issues with doing a variety of things from an imported session. However, I am having an issue with a particular line in this script:

 

$Mailboxes = Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize:Unlimited | Select-Object Alias, DisplayName, @{label="LastLogonTime";expression={(Get-MailboxStatistics $_).LastLogonTime}}, @{label="ItemCount";expression={(Get-MailboxStatistics $_).ItemCount}}

 

The issue is that the LastLogonTime and ItemCount do not get populated when run remotely (they are populated when run locally on the Exchange server). Running the individual “Get-MailboxStatistics” commands from the remote session returns the expected values—it just doesn’t seem to be able to put it together in one line.

 

Is there some limitation with the imported session or is there something else that I am missing here? Any pointers would be appreciated.

 

 

Bill Mayo

 

Michael B. Smith

unread,
May 18, 2021, 10:35:34 AM5/18/21
to ntexc...@googlegroups.com

Imported sessions require data to be dual-serialized (this happens all the time in Exchange online sessions, which is where I first ran into it).

 

Often the rehydrated (deserialized) variables have changed type (e.g., a [DateTime] becomes a [String]). I expect that is what happened to you below, with your $_ - the data types are no longer the same. Use a more constrained variable instead, like $_.distinguishedName.

--
You received this message because you are subscribed to the Google Groups "ntexchange" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ntexchange+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ntexchange/3b10acdfb1f5490480fc2ea27984743f%40pittcountync.gov.

Mayo, Bill

unread,
May 18, 2021, 10:39:59 AM5/18/21
to ntexc...@googlegroups.com

Making that changed fixed the issue. Thanks so much for the quick response.

Reply all
Reply to author
Forward
0 new messages