header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Obtaining proxyaddresses with multiple x400 addresses
Last Post 18 Dec 2009 07:47 AM by Bobdee. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BobdeeUser is Offline
Basic Member
Basic Member
Posts:130
Avatar

--
18 Dec 2009 05:20 AM

    Hi,

    I'm trawling my domain for AD accounts with multiple x400 addresses using the -Like switch.  The results are being written to a local DB, to query late.

    However, using -Like only returns 'True' or 'False' for the proxyaddresses, and returns all user accounts with that true or false value (not great with a large AD).  What I was hoping to obtain was the actual value of the proxyaddresses attribute, and ONLY the accounts that contain multiple

    Can anyone tell me if -Like is the best option, and if not what might be more efficient?

    Script -

    Get-qaduser -IncludeAllProperties -SerializeValues -SizeLimit 0 | select samaccountname,proxyaddresses | foreach {
    $sql= "INSERT INTO robdb.dbo.Test_tbl ( samaccountname,proxyaddresses ) VALUES ( '{0}','{1}' )" -f $_.SamAccountName, ( $_.proxyaddresses -join ";" -like "*X400:c*X400:c*" )

    invoke-sqlcmd $sql

    }

    Thanks,

    Rob

    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    18 Dec 2009 05:59 AM
    Don't use -IncludeAllProperties just to get proxyaddresses, you can use -IncludedProperties and specify just the ones you need.
    You also need to reorder the -like command, first do like and then join the values:


    Get-qaduser -IncludedProperties proxyaddresses -SizeLimit 0 | select samaccountname,proxyaddresses | foreach {
    $sql= "INSERT INTO robdb.dbo.Test_tbl ( samaccountname,proxyaddresses ) VALUES ( '{0}','{1}' )" -f $_.SamAccountName, (($_.proxyaddresses -like "X400:c*") -join ";" )
    invoke-sqlcmd $sql
    }



    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    18 Dec 2009 07:01 AM
    Thanks Shay, I was using -IncludeAllProperties as I hope to include extensionattributes also - this will allow me to tie the dataset from this script into a user provisioning database I have.

    The addition to the script gave the x400 address, but included all objects with an x400 address. What I hoped to achieve was to write only the objects to the database that had 2 or more x400 addresses if that makes sense. We have a very large AD and writing all the x400 addtresses is not a great solution for me.

    Basically, I was hoping for

    SamAccountName, X400......X400

    I don't mind if the entire proxyaddresses string is included as I can remove the scrap later.

    Is this possible at all?

    Thanks for the prompt reply

    Robbie.
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    18 Dec 2009 07:04 AM
    Get-qaduser... | where {($_.proxyaddresses -like "X400:c*") -ge 2} | foreach { ...

    Shay Levy
    Windows PowerShell MVP
    http://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    BobdeeUser is Offline
    Basic Member
    Basic Member
    Posts:130
    Avatar

    --
    18 Dec 2009 07:47 AM
    Thanks again Shay - I'm getting similar results however. I've put together all you've said and I guess I could just write all the proxyaddresses to my table - it may come in useful! I just not too sure of the correct method to take this ADSI data into SQL - I've used SQLs LDAP but its too fragile so hoped PS could give me what I need.

    Invoke-expression sqlcmd
    Invoke-Sqlcmd "if exists (select * from robdb.dbo.sysobjects where name = 'Test_tbl') drop table robdb.dbo.test_tbl"
    Invoke-Sqlcmd "create table robdb.dbo.Test_tbl ( samaccountname varchar(50), proxyaddresses varchar(500) )"


    Get-qaduser -IncludedProperties proxyaddresses -SizeLimit 0 | select samAccountName,proxyAddresses | where {($_.proxyaddresses -like "X400:c*") -ge 2 } | foreach {

    $sql= "INSERT INTO robdb.dbo.Test_tbl ( samaccountname,proxyaddresses ) VALUES ( '{0}','{1}' )" -f $_.SamAccountName, ( $_.proxyaddresses -join ";" )

    write-host $sql

    }

    Thanks

    Rob
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer