Windows Vista Forums

Updating AD proxyAddresses

  1. #1


    Shawn Dumas Guest

    Updating AD proxyAddresses

    param ([array]$users=$(throw "Need Users..."))
    foreach ($user in $users)
    {
    $u = (ldap
    "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDirectoryEntry()
    if ($u.proxyAddresses)
    {
    $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    $pa = '@("' + ([string]::join('","', $pa)) + '")'
    $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    $u.SetInfo()
    }
    }



    This works but why on earth do I have to get so jiggy with the array before
    PutEx will take it?

      My System SpecsSystem Spec

  2. #2


    Oisin Grehan Guest

    Re: Updating AD proxyAddresses

    On Sep 13, 8:12 pm, Shawn Dumas <ShawnDu...@xxxxxx>
    wrote:

    > param ([array]$users=$(throw "Need Users..."))
    > foreach ($user in $users)
    > {
    > $u = (ldap
    > "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDi*rectoryEntry()
    > if ($u.proxyAddresses)
    > {
    > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > $pa = '@("' + ([string]::join('","', $pa)) + '")'
    > $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    > $u.SetInfo()
    > }
    >
    > }
    >
    > This works but why on earth do I have to get so jiggy with the array before
    > PutEx will take it?
    I remember going through similar hoops trying to get arrays as
    parameters passed correctly; a bit painful. I still muck it up now and
    again. Powershell has a habit of unrolling arrays before passing them
    anywhere, so try using the array constructor:

    $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    $u.PutEx(2, 'proxyAddresses', (,$pa))

    I'm not able to test this, so it might not work outright, but
    Hopefully it'll give you some ideas. So, why do this? By putting the
    array constructor in front of it, I'm making an array with 1 element,
    which is your $pa array. Powershell will unroll it, leaving the inner
    array intact (hopefully!)

    Hope this helps

    - Oisin


      My System SpecsSystem Spec

  3. #3


    Brandon Shell Guest

    Re: Updating AD proxyAddresses

    I would assume it because that is a multi value attribute and with
    ADS_PROPERTY_UPDATE (aka 2) it expects an arrayish value.

    Are you trying to replace all the values or just one particular one?


    "Shawn Dumas" <ShawnDumas@xxxxxx> wrote in message
    news:BFCB8EDB-E670-4640-AD90-31A1F85D08C4@xxxxxx

    > param ([array]$users=$(throw "Need Users..."))
    > foreach ($user in $users)
    > {
    > $u = (ldap
    > "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDirectoryEntry()
    > if ($u.proxyAddresses)
    > {
    > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > $pa = '@("' + ([string]::join('","', $pa)) + '")'
    > $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    > $u.SetInfo()
    > }
    > }
    >
    > This works but why on earth do I have to get so jiggy with the array
    > before
    > PutEx will take it?

      My System SpecsSystem Spec

  4. #4


    Shawn Dumas Guest

    Re: Updating AD proxyAddresses

    I'll give that a shot, thanks!

    "Oisin Grehan" wrote:

    > On Sep 13, 8:12 pm, Shawn Dumas <ShawnDu...@xxxxxx>
    > wrote:

    > > param ([array]$users=$(throw "Need Users..."))
    > > foreach ($user in $users)
    > > {
    > > $u = (ldap
    > > "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDi-rectoryEntry()
    > > if ($u.proxyAddresses)
    > > {
    > > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > > $pa = '@("' + ([string]::join('","', $pa)) + '")'
    > > $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    > > $u.SetInfo()
    > > }
    > >
    > > }
    > >
    > > This works but why on earth do I have to get so jiggy with the array before
    > > PutEx will take it?
    >
    > I remember going through similar hoops trying to get arrays as
    > parameters passed correctly; a bit painful. I still muck it up now and
    > again. Powershell has a habit of unrolling arrays before passing them
    > anywhere, so try using the array constructor:
    >
    > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > $u.PutEx(2, 'proxyAddresses', (,$pa))
    >
    > I'm not able to test this, so it might not work outright, but
    > Hopefully it'll give you some ideas. So, why do this? By putting the
    > array constructor in front of it, I'm making an array with 1 element,
    > which is your $pa array. Powershell will unroll it, leaving the inner
    > array intact (hopefully!)
    >
    > Hope this helps
    >
    > - Oisin
    >
    >

      My System SpecsSystem Spec

  5. #5


    Brandon Shell Guest

    Re: Updating AD proxyAddresses

    Try adding [array] in front of $pa
    [array]$pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    $pa += New-Value
    $u.PutEx(2, 'proxyAddresses', $pa)
    $u.setinfo()

    "Brandon Shell" <tshell.mask@xxxxxx> wrote in message
    news:%23vDU0Xm9HHA.4612@xxxxxx

    >I would assume it because that is a multi value attribute and with
    >ADS_PROPERTY_UPDATE (aka 2) it expects an arrayish value.
    >
    > Are you trying to replace all the values or just one particular one?
    >
    >
    > "Shawn Dumas" <ShawnDumas@xxxxxx> wrote in message
    > news:BFCB8EDB-E670-4640-AD90-31A1F85D08C4@xxxxxx

    >> param ([array]$users=$(throw "Need Users..."))
    >> foreach ($user in $users)
    >> {
    >> $u = (ldap
    >> "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDirectoryEntry()
    >> if ($u.proxyAddresses)
    >> {
    >> $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    >> $pa = '@("' + ([string]::join('","', $pa)) + '")'
    >> $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    >> $u.SetInfo()
    >> }
    >> }
    >>
    >> This works but why on earth do I have to get so jiggy with the array
    >> before
    >> PutEx will take it?
    >

      My System SpecsSystem Spec

  6. #6


    Shawn Dumas Guest

    Re: Updating AD proxyAddresses

    $u.PutEx(2, 'proxyAddresses', (,"$pa"))

    All I had to do was add quotes to what you posted and then, pow; it worked!
    Thanks again.

    "Oisin Grehan" wrote:

    > On Sep 13, 8:12 pm, Shawn Dumas <ShawnDu...@xxxxxx>
    > wrote:

    > > param ([array]$users=$(throw "Need Users..."))
    > > foreach ($user in $users)
    > > {
    > > $u = (ldap
    > > "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDi-rectoryEntry()
    > > if ($u.proxyAddresses)
    > > {
    > > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > > $pa = '@("' + ([string]::join('","', $pa)) + '")'
    > > $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    > > $u.SetInfo()
    > > }
    > >
    > > }
    > >
    > > This works but why on earth do I have to get so jiggy with the array before
    > > PutEx will take it?
    >
    > I remember going through similar hoops trying to get arrays as
    > parameters passed correctly; a bit painful. I still muck it up now and
    > again. Powershell has a habit of unrolling arrays before passing them
    > anywhere, so try using the array constructor:
    >
    > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > $u.PutEx(2, 'proxyAddresses', (,$pa))
    >
    > I'm not able to test this, so it might not work outright, but
    > Hopefully it'll give you some ideas. So, why do this? By putting the
    > array constructor in front of it, I'm making an array with 1 element,
    > which is your $pa array. Powershell will unroll it, leaving the inner
    > array intact (hopefully!)
    >
    > Hope this helps
    >
    > - Oisin
    >
    >

      My System SpecsSystem Spec

  7. #7


    Shawn Dumas Guest

    Re: Updating AD proxyAddresses

    I am replacing.

    "Brandon Shell" wrote:

    > I would assume it because that is a multi value attribute and with
    > ADS_PROPERTY_UPDATE (aka 2) it expects an arrayish value.
    >
    > Are you trying to replace all the values or just one particular one?
    >
    >
    > "Shawn Dumas" <ShawnDumas@xxxxxx> wrote in message
    > news:BFCB8EDB-E670-4640-AD90-31A1F85D08C4@xxxxxx

    > > param ([array]$users=$(throw "Need Users..."))
    > > foreach ($user in $users)
    > > {
    > > $u = (ldap
    > > "(&(objectCategory=person)(objectClass=user)(samaccountname=$user))").GetDirectoryEntry()
    > > if ($u.proxyAddresses)
    > > {
    > > $pa = $u.proxyAddresses | ?{$_ -match 'bad-address'}
    > > $pa = '@("' + ([string]::join('","', $pa)) + '")'
    > > $u.PutEx(2, 'proxyAddresses', (invoke-expression "$pa"))
    > > $u.SetInfo()
    > > }
    > > }
    > >
    > > This works but why on earth do I have to get so jiggy with the array
    > > before
    > > PutEx will take it?
    >
    >

      My System SpecsSystem Spec

Updating AD proxyAddresses

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Chrome Boy Live Mail 2 16 Mar 2009
updating RC1? Liam Vista General 7 30 Jan 2007
Updating wow waldpiek Vista Games 1 19 Oct 2006
Updating to RC2 Louis Lebrun Vista General 6 07 Oct 2006
updating Tmac2409 Vista file management 0 08 Jun 2006