header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Seperating a returned object into several objects
Last Post 24 Oct 2008 04:21 PM by SynJunkie. 13 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
21 Oct 2008 03:30 PM  

Hi guys

I have a problem.  I need to compile a list of all email addresses in use at my organisation.  Now I can easily get the primary email address from AD but the ones where I have a problem is where a user has a few alternate email addresses.

 

I have found the field and I can access pull it from AD with the following query:

get-qaduser "joe bloggs" -includeallproperties | select proxyaddresses

 

This returns all the alternate addresses in the following form:

{smtp:joe.bloggs@companyA.com, smtp:j.bloggs@companyA.com}

 

I need to be able to break that object down so my end result a spreadsheet that looks like:

joe.bloggs@companyA.com

j.bloggs@companyA.com

 

Does anyone have any ideas how this might be done?

Thanks.

Lee

bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
21 Oct 2008 05:01 PM  
Try this
get-qaduser "joe bloggs" -includeallproperties | select -expan proxyaddresses
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
21 Oct 2008 05:01 PM  
That was supposed to be -expand, but the -expan will work as well :)
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 10:34 AM  
That works well. now I can pipe through Where-object { $_ -notmatch "x" } to remove the X400 addresses. 2 more things though. This is pretty slow, do you know of a quicker way of going through AD? and do you know of a way to remove the "SMTP:" from the front of the returned object?
ShayUser is Offline
Basic Member
Basic Member
Posts:269
Avatar

--
24 Oct 2008 01:39 PM  

...where {$_ -like "smtp:*"} | foreach {$_.substring(5)}

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 02:57 PM  
Thanks Shay. That gives me the exact output I require without having to manipulate the results in excel.

get-qaduser "*" -includeallproperties | select -expand proxyaddresses | where {$_ -notmatch "x" } | where {$_ -like "smtp:*"} | foreach {$_.substring(5)}

I do however recieve warnings "Select-Object : Cannot expand property "proxyaddresses" because it has nothing to expand." if I perform the same using Get-QADObject (I need email addresses for mail enabled groups also).



Is there a way to suppress this warning do you know?
ShayUser is Offline
Basic Member
Basic Member
Posts:269
Avatar

--
24 Oct 2008 03:08 PM  

I would make some chnages to your command:

1. Don't use -includeallproperties when all you need is just the proxyaddresses property, use -includedProperties instaead (-ip for short).

2. To get ALL user objects, use the '-sizeLimt 0' parameter.
3. Use an ldap query to filter just the objects that has a proxyaddresses value.


PS > get-qaduser -sizeLimt 0 -ldap '(proxyaddresses=*)' -ip proxyaddresses | select -expand proxyaddresses | where {$_ -notmatch "x" -and $_ -like "smtp:*"} | foreach {$_.substring(5)}

If the above command still generates the '..nothing to expand' error then you can add a where-object filter to pass on none null proxyaddresses properties or just add '-errorAction silentlyContinue' to select-object to supress the error:

PS > get-qaduser -sizeLimt 0 -ldap '(proxyaddresses=*)' -ip proxyaddresses | where {$_.proxyaddresses} | select -expand proxyaddresses | ...

- or -


PS > get-qaduser -sizeLimt 0 -ldap '(proxyaddresses=*)' -ip proxyaddresses | select -expand proxyaddresses -ea silentlyContinue | ...

Or a combination of both ;-)

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 03:36 PM  
Those are fantastic suggestions and I get most of it. Could you explain the where-object to pass on no null proxyaddresses though. that bit confused me.
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 03:40 PM  
Hang on. will it be ..... where { $_.proxyaddresses -neq "null" } ?
ShayUser is Offline
Basic Member
Basic Member
Posts:269
Avatar

--
24 Oct 2008 03:44 PM  
Exactly, I would write it like so:

... | where { $_.proxyaddresses -ne $null} | ...

Or simply (which is also equel to $true) ;-)

... | where { $_.proxyaddresses} | ...

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 03:45 PM  
i mean -notmatch.

This works really well and is pretty fast.

get-qadobject "*" -sizeLimit 0 -ldap '(proxyaddresses=*)' -ip proxyaddresses | select -expand proxyaddresses | where {$_ -notmatch "x" -and $_ -like "smtp:*"} | foreach {$_.substring(5)} | where { $_.proxyaddresses -notmatch "null" }
ShayUser is Offline
Basic Member
Basic Member
Posts:269
Avatar

--
24 Oct 2008 03:53 PM  
You're using it in the wrong place, I used it before the pipe to select-object to avoid the error you mentioned.
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
bsonposhUser is Offline
Basic Member
Basic Member
Posts:392
Avatar

--
24 Oct 2008 04:06 PM  
I would change

where {$_ -notmatch "x" -and $_ -like "smtp:*"}

to, or what ever regex fits... no reason to compare twice

where {$_ -match "smtp\:.*"}
Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Blog: http://www.bsonposh.com
SynJunkieUser is Offline
New Member
New Member
Posts:97
Avatar

--
24 Oct 2008 04:21 PM  
that makes sense.

I'll rerun and see if its quicker.
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer