Windows Vista Forums

Writing an array back in to an AD Object

  1. #1


    Mark Holland Guest

    Writing an array back in to an AD Object

    Hello,



    I'm basically reading the "proxyaddresses" attribute from an Active
    Directory user object, making some changes and writing it back.

    The problem is, it writes back as a single string instead of an array.
    Basically as a test I tried just reading the array and then writing it
    STRAIGHT back. The problem occurs here to....

    $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")

    $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    $oUserDN.SetInfo()

    Now when I look in Active Directory Computers & Users its in as a single line.

    Oh FYI - After you write in back and the RUS detects its in a invalid format
    it re-stamps it automatically - confused me for a while......

    How do I write it back as an array?

    Many Thanks

    Mark holland

      My System SpecsSystem Spec

  2. #2


    Brandon Shell [MVP] Guest

    Re: Writing an array back in to an AD Object

    I cant test this right now, but you should be able to do this.

    $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    $oUserDN.psbase.proxyaddresses += "NewAddress"
    $oUserDN.SetInfo()

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    MH> Hello,
    MH>
    MH> I'm basically reading the "proxyaddresses" attribute from an Active
    MH> Directory user object, making some changes and writing it back.
    MH>
    MH> The problem is, it writes back as a single string instead of an
    MH> array. Basically as a test I tried just reading the array and then
    MH> writing it STRAIGHT back. The problem occurs here to....
    MH>
    MH> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    MH> $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")
    MH>
    MH> $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    MH> $oUserDN.SetInfo()
    MH>
    MH> Now when I look in Active Directory Computers & Users its in as a
    MH> single line.
    MH>
    MH> Oh FYI - After you write in back and the RUS detects its in a
    MH> invalid format it re-stamps it automatically - confused me for a
    MH> while......
    MH>
    MH> How do I write it back as an array?
    MH>
    MH> Many Thanks
    MH>
    MH> Mark holland
    MH>



      My System SpecsSystem Spec

  3. #3


    kelly goff Guest

    Re: Writing an array back in to an AD Object

    Look at the article http://powershelllive.com/blogs/lunch/default.aspx
    in the section on "Dealing with Properties that Contain Arrays"

    Kelly

      My System SpecsSystem Spec

  4. #4


    Mark Holland Guest

    Re: Writing an array back in to an AD Object

    Thanks Brandon but no joy I'm afraid...

    It comes up with "Property 'proxyaddresses' cannot be found on this object;
    make sure it exists and is settable."

    Any other ideas?

    Mark

    "Brandon Shell [MVP]" wrote:

    > I cant test this right now, but you should be able to do this.
    >
    > $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > $oUserDN.psbase.proxyaddresses += "NewAddress"
    > $oUserDN.SetInfo()
    >
    > Brandon Shell
    > ---------------
    > Blog: http://www.bsonposh.com/
    > PSH Scripts Project: www.codeplex.com/psobject
    >
    > MH> Hello,
    > MH>
    > MH> I'm basically reading the "proxyaddresses" attribute from an Active
    > MH> Directory user object, making some changes and writing it back.
    > MH>
    > MH> The problem is, it writes back as a single string instead of an
    > MH> array. Basically as a test I tried just reading the array and then
    > MH> writing it STRAIGHT back. The problem occurs here to....
    > MH>
    > MH> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > MH> $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")
    > MH>
    > MH> $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    > MH> $oUserDN.SetInfo()
    > MH>
    > MH> Now when I look in Active Directory Computers & Users its in as a
    > MH> single line.
    > MH>
    > MH> Oh FYI - After you write in back and the RUS detects its in a
    > MH> invalid format it re-stamps it automatically - confused me for a
    > MH> while......
    > MH>
    > MH> How do I write it back as an array?
    > MH>
    > MH> Many Thanks
    > MH>
    > MH> Mark holland
    > MH>
    >
    >
    >

      My System SpecsSystem Spec

  5. #5


    Mark Holland Guest

    Re: Writing an array back in to an AD Object

    Thanks Geoff - that site is currently down but will keep trying...

    "kelly goff" wrote:

    > Look at the article http://powershelllive.com/blogs/lunch/default.aspx
    > in the section on "Dealing with Properties that Contain Arrays"
    >
    > Kelly
    >

      My System SpecsSystem Spec

  6. #6


    Brandon Shell [MVP] Guest

    Re: Writing an array back in to an AD Object

    You can try to ref proxy directly
    $oUserDN.proxyaddresses += "NewAddress"
    and I left out the properties. Try this.
    $oUserDN.psbase.properties.proxyaddresses += "NewAddress"

    "Mark Holland" <MarkHolland@xxxxxx> wrote in message
    news:6B857AD4-5F83-4D8C-BDEB-841834B3EC28@xxxxxx

    > Thanks Brandon but no joy I'm afraid...
    >
    > It comes up with "Property 'proxyaddresses' cannot be found on this
    > object;
    > make sure it exists and is settable."
    >
    > Any other ideas?
    >
    > Mark
    >
    > "Brandon Shell [MVP]" wrote:
    >

    >> I cant test this right now, but you should be able to do this.
    >>
    >> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    >> $oUserDN.psbase.proxyaddresses += "NewAddress"
    >> $oUserDN.SetInfo()
    >>
    >> Brandon Shell
    >> ---------------
    >> Blog: http://www.bsonposh.com/
    >> PSH Scripts Project: www.codeplex.com/psobject
    >>
    >> MH> Hello,
    >> MH>
    >> MH> I'm basically reading the "proxyaddresses" attribute from an Active
    >> MH> Directory user object, making some changes and writing it back.
    >> MH>
    >> MH> The problem is, it writes back as a single string instead of an
    >> MH> array. Basically as a test I tried just reading the array and then
    >> MH> writing it STRAIGHT back. The problem occurs here to....
    >> MH>
    >> MH> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    >> MH> $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")
    >> MH>
    >> MH> $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    >> MH> $oUserDN.SetInfo()
    >> MH>
    >> MH> Now when I look in Active Directory Computers & Users its in as a
    >> MH> single line.
    >> MH>
    >> MH> Oh FYI - After you write in back and the RUS detects its in a
    >> MH> invalid format it re-stamps it automatically - confused me for a
    >> MH> while......
    >> MH>
    >> MH> How do I write it back as an array?
    >> MH>
    >> MH> Many Thanks
    >> MH>
    >> MH> Mark holland
    >> MH>
    >>
    >>
    >>

      My System SpecsSystem Spec

  7. #7


    Mark Holland Guest

    Re: Writing an array back in to an AD Object

    Hi Brandon,

    Sorry - I see where you are going with the "add" to the existing value
    concept. However my ultimate aim is to get the array, remove entries in it
    that match a certain criteria and write it back. In summary the "add" to
    concept unfortunately won't work for me.

    FYI though - by referencing the proxy directly it does write back to the
    attribute but as per my original issue it put it is as a single string.

    Any further ideas?

    Thanks

    Mark

    "Brandon Shell [MVP]" wrote:

    > You can try to ref proxy directly
    > $oUserDN.proxyaddresses += "NewAddress"
    > and I left out the properties. Try this.
    > $oUserDN.psbase.properties.proxyaddresses += "NewAddress"
    >
    > "Mark Holland" <MarkHolland@xxxxxx> wrote in message
    > news:6B857AD4-5F83-4D8C-BDEB-841834B3EC28@xxxxxx

    > > Thanks Brandon but no joy I'm afraid...
    > >
    > > It comes up with "Property 'proxyaddresses' cannot be found on this
    > > object;
    > > make sure it exists and is settable."
    > >
    > > Any other ideas?
    > >
    > > Mark
    > >
    > > "Brandon Shell [MVP]" wrote:
    > >

    > >> I cant test this right now, but you should be able to do this.
    > >>
    > >> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > >> $oUserDN.psbase.proxyaddresses += "NewAddress"
    > >> $oUserDN.SetInfo()
    > >>
    > >> Brandon Shell
    > >> ---------------
    > >> Blog: http://www.bsonposh.com/
    > >> PSH Scripts Project: www.codeplex.com/psobject
    > >>
    > >> MH> Hello,
    > >> MH>
    > >> MH> I'm basically reading the "proxyaddresses" attribute from an Active
    > >> MH> Directory user object, making some changes and writing it back.
    > >> MH>
    > >> MH> The problem is, it writes back as a single string instead of an
    > >> MH> array. Basically as a test I tried just reading the array and then
    > >> MH> writing it STRAIGHT back. The problem occurs here to....
    > >> MH>
    > >> MH> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > >> MH> $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")
    > >> MH>
    > >> MH> $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    > >> MH> $oUserDN.SetInfo()
    > >> MH>
    > >> MH> Now when I look in Active Directory Computers & Users its in as a
    > >> MH> single line.
    > >> MH>
    > >> MH> Oh FYI - After you write in back and the RUS detects its in a
    > >> MH> invalid format it re-stamps it automatically - confused me for a
    > >> MH> while......
    > >> MH>
    > >> MH> How do I write it back as an array?
    > >> MH>
    > >> MH> Many Thanks
    > >> MH>
    > >> MH> Mark holland
    > >> MH>
    > >>
    > >>
    > >>
    >

      My System SpecsSystem Spec

  8. #8


    Mark Holland Guest

    Re: Writing an array back in to an AD Object

    Thanks for all your help on this.

    I managed to get round this by reading the array in a 'for' loop and
    commiting each entry seperately i.e.

    foreach($vProxyAddresses in $oProxyArrayTemp){

    $oUserDN.proxyaddresses[$vcount] = $vProxyAddresses
    $vcount++
    }

    $oUserDN.SetInfo()

    Mark

    "Mark Holland" wrote:

    > Hi Brandon,
    >
    > Sorry - I see where you are going with the "add" to the existing value
    > concept. However my ultimate aim is to get the array, remove entries in it
    > that match a certain criteria and write it back. In summary the "add" to
    > concept unfortunately won't work for me.
    >
    > FYI though - by referencing the proxy directly it does write back to the
    > attribute but as per my original issue it put it is as a single string.
    >
    > Any further ideas?
    >
    > Thanks
    >
    > Mark
    >
    > "Brandon Shell [MVP]" wrote:
    >

    > > You can try to ref proxy directly
    > > $oUserDN.proxyaddresses += "NewAddress"
    > > and I left out the properties. Try this.
    > > $oUserDN.psbase.properties.proxyaddresses += "NewAddress"
    > >
    > > "Mark Holland" <MarkHolland@xxxxxx> wrote in message
    > > news:6B857AD4-5F83-4D8C-BDEB-841834B3EC28@xxxxxx

    > > > Thanks Brandon but no joy I'm afraid...
    > > >
    > > > It comes up with "Property 'proxyaddresses' cannot be found on this
    > > > object;
    > > > make sure it exists and is settable."
    > > >
    > > > Any other ideas?
    > > >
    > > > Mark
    > > >
    > > > "Brandon Shell [MVP]" wrote:
    > > >
    > > >> I cant test this right now, but you should be able to do this.
    > > >>
    > > >> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > > >> $oUserDN.psbase.proxyaddresses += "NewAddress"
    > > >> $oUserDN.SetInfo()
    > > >>
    > > >> Brandon Shell
    > > >> ---------------
    > > >> Blog: http://www.bsonposh.com/
    > > >> PSH Scripts Project: www.codeplex.com/psobject
    > > >>
    > > >> MH> Hello,
    > > >> MH>
    > > >> MH> I'm basically reading the "proxyaddresses" attribute from an Active
    > > >> MH> Directory user object, making some changes and writing it back.
    > > >> MH>
    > > >> MH> The problem is, it writes back as a single string instead of an
    > > >> MH> array. Basically as a test I tried just reading the array and then
    > > >> MH> writing it STRAIGHT back. The problem occurs here to....
    > > >> MH>
    > > >> MH> $oUserDN = [ADSI]"LDAP://$cn=testuser, CN=users, DC=company, DC=com"
    > > >> MH> $aUserProxyAddresses = $oUserDN.Get("proxyaddresses")
    > > >> MH>
    > > >> MH> $oUserDN.Put("proxyaddresses", "$aUserProxyAddresses")
    > > >> MH> $oUserDN.SetInfo()
    > > >> MH>
    > > >> MH> Now when I look in Active Directory Computers & Users its in as a
    > > >> MH> single line.
    > > >> MH>
    > > >> MH> Oh FYI - After you write in back and the RUS detects its in a
    > > >> MH> invalid format it re-stamps it automatically - confused me for a
    > > >> MH> while......
    > > >> MH>
    > > >> MH> How do I write it back as an array?
    > > >> MH>
    > > >> MH> Many Thanks
    > > >> MH>
    > > >> MH> Mark holland
    > > >> MH>
    > > >>
    > > >>
    > > >>
    > >

      My System SpecsSystem Spec

Writing an array back in to an AD Object

Similar Threads
Thread Thread Starter Forum Replies Last Post
adding a custom object to array jorgemestre PowerShell 1 09 Jul 2009
Deserialize array as object sebastian.dau@googlemail.com Indigo 2 16 Apr 2008
array or object??? Ryan PowerShell 5 11 Mar 2008
preventing PS from Casting object to an array Marclown PowerShell 3 31 Jan 2008
Creating an array of floats using new-object Kris PowerShell 2 27 Nov 2007