Powershell script to return only total amounts and Exchange 2003 mailbox

I am working on a Powershell script that will only return common items and an Exchange 2003 mailbox. For now, I have this:

get-wmiobject -putputername exchange01 -namespace root \ microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname = 'Journal Mail'" | select-object totalitems | host entries

However, this gives results like:

@ {TotalItems = 939}

I want the number to be returned, since we have an external program that will read this number and send a notification if it exceeds the given number.

I'm having trouble finding a way to extract all the unnecessary information from the results. Any suggestions are welcome how I can do this.

+4
source share
2 answers

Select-Object returns an object with one property, assigns the result to a variable, and refers to the name of the property:

$mbx = get-wmiobject -computername exchange01 -namespace root\microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname='Journal Mail'" $mbx.totalitems 
+1
source

Try it if it works:

 get-wmiobject -computername exchange01 -namespace root\microsoftexchangev2 -class exchange_mailbox -filter "mailboxdisplayname='Journal Mail'" | select-object -ExpandProperty totalitems 
0
source

Source: https://habr.com/ru/post/1441584/


All Articles