Solved

Exchange Powershell question for filtering results of a query

Posted on 2014-02-12
4
1,145 Views
Last Modified: 2014-02-13
I have a command that gets me the information of a users Safe Senders:
Get-MailboxJunkEmailConfiguration JohnDoe |Select-Object -ExpandProperty trustedsendersanddomains | sort-object

if you run
Get-MailboxJunkEmailConfiguration JohnDoe
the results would have each email address within a parenthesis separated by commas.

If you run 1st command I listed you get the emails in a column. If the user entered specific email addresses like JaneDoe@hotmail.com, you see that in the result.
if they tried to add a Domain to their safesender, the Outlook UI lists it like @Hotmail.com

the powershell command will result showing the Hotmail domain as just Hotmail.com

w/o the @ sign



So, what I am looking for is, the right syntax to get only the addresses that are complete (not the domain entries).
I tried to filter my search by only showing the items that have the @ sign

Get-MailboxJunkEmailConfiguration JohnDoe |Select-Object -ExpandProperty trustedsendersanddomains | ? {$_.trustedsendersanddomains -like "*@*"} | sort-object

which does not work.   :(
0
Comment
Question by:taartero
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39855089
Since you used the -expandProperty parameter, the objects that are sent down the pipeline from Select-Object do not have the trustedsendersanddomains property.  You can see this by running:
Get-MailboxJunkEmailConfiguration JohnDoe |Select-Object -ExpandProperty trustedsendersanddomains | Get-Member

Open in new window

So, you just need to adjust your code like this:
Get-MailboxJunkEmailConfiguration JohnDoe | Select-Object -ExpandProperty trustedsendersanddomains | ? {$_ -like "*@*"} | sort-object

Open in new window

I think it will work, but let me know if there are problems because I haven't tested.
0
 

Author Comment

by:taartero
ID: 39856333
I found, running your 1st command to be very interesting to me:
Get-MailboxJunkEmailConfiguration JohnDoe |Select-Object -ExpandProperty trustedsendersanddomains | Get-Member


Name             MemberType            Definition
----             ----------            ----------
Clone            Method                System.Object Clone(), System.Obje
CompareTo        Method                int CompareTo(System.Object value)
Contains         Method                bool Contains(string value)
CopyTo           Method                void CopyTo(int sourceIndex, char[
EndsWith         Method                bool EndsWith(string value), bool
Equals           Method                bool Equals(System.Object obj), bo
GetEnumerator    Method                System.CharEnumerator GetEnumerato
GetHashCode      Method                int GetHashCode()
GetType          Method                type GetType()
GetTypeCode      Method                System.TypeCode GetTypeCode(), Sys
IndexOf          Method                int IndexOf(char value), int Index
IndexOfAny       Method                int IndexOfAny(char[] anyOf), int
Insert           Method                string Insert(int startIndex, stri
IsNormalized     Method                bool IsNormalized(), bool IsNormal
LastIndexOf      Method                int LastIndexOf(char value), int L
LastIndexOfAny   Method                int LastIndexOfAny(char[] anyOf),
Normalize        Method                string Normalize(), string Normali
PadLeft          Method                string PadLeft(int totalWidth), st
PadRight         Method                string PadRight(int totalWidth), s
Remove           Method                string Remove(int startIndex, int
Replace          Method                string Replace(char oldChar, char
Split            Method                string[] Split(Params char[] separ
StartsWith       Method                bool StartsWith(string value), boo
Substring        Method                string Substring(int startIndex),
ToBoolean        Method                bool IConvertible.ToBoolean(System
.....




I was looking through those results trying to make sense of what I was reading. I thought as I was going down that list, that I was going to find the "-expandproperty".
After going through that list, I couldn't see what I think you were trying to tell me.
I am still very interested in you explaining what the "get-member' is actually telling me (since im guessing it is getting me the member {properties} of the result)


Anyhow, I then ran your second command:
Get-MailboxJunkEmailConfiguration JohnDoe | Select-Object -ExpandProperty trustedsendersanddomains | ? {$_ -like "*@*"} | sort-object

and the answer for me is in the pipe ""  ? {$_ -like "*@*"} ""
Where the $_ is left blank... vs.  $_.VALUE

Thanks so much, it worked like a CHAMP
0
 

Author Closing Comment

by:taartero
ID: 39856336
Thanks so Much!

hopefully you still answer the comment I made
0
 
LVL 40

Expert Comment

by:footech
ID: 39856398
It may make more sense to you if you run
Get-MailboxJunkEmailConfiguration JohnDoe | gm

Open in new window

(gm is an alias for Get-Member) and compare the results to what you saw earlier.  Basically what you saw was the properties and methods available for a string, which is what the "trustedsendersanddomains" property is.  At the top of the output you should see the type of the object that is output, like "TypeName: System.String".  When you run the code in this post you will see all the properties and methods available for the objects sent to the Get-Member cmdlet (i.e. the objects output by Get-MailboxJunkEmailConfiguration).

Get-Member is very useful when you're developing a script and are trying to discover what information is available to you and what you can do with it.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question