Windows Vista Forums

Does property/Attribure exist?

  1. #1


    Tim Munro Guest

    Does property/Attribure exist?

    hi all,
    I'm trying to find how to determine if a property or attribute exists in
    an AD object. Specifically the accountexpirationdate. If I just look for and
    it's not there, and exception is thrown.



    Quick example:

    $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    If ($oUser.ifAttributeexists($myAttribute)) {
    do stuff
    }

    Is there a way to accomplish this?

    Thanks.
    --
    Tim.





      My System SpecsSystem Spec

  2. #2


    Jan Egil Ring Guest

    Re: Does property/Attribure exist?

    Hi!

    If using Quest`s Active Directory cmdlets are an option, you can accomplish
    this by using this one-liner:
    Get-QADUser | Where-Object {$_.accountexpires -ne $null}

    You can get Quest`s AD cmlets from here:
    http://www.quest.com/activeroles-server/arms.aspx

    --
    Jan Egil Ring
    ---------------------
    http://janegilring.wordpress.com
    http://powershellug.ning.com

    "Tim Munro" <Excelsior@xxxxxx> wrote in message
    news:uEn4yUoJKHA.1252@xxxxxx

    > hi all,
    > I'm trying to find how to determine if a property or attribute exists
    > in an AD object. Specifically the accountexpirationdate. If I just look
    > for and it's not there, and exception is thrown.
    >
    > Quick example:
    >
    > $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    > If ($oUser.ifAttributeexists($myAttribute)) {
    > do stuff
    > }
    >
    > Is there a way to accomplish this?
    >
    > Thanks.
    > --
    > Tim.
    >
    >
    >
    >

      My System SpecsSystem Spec

  3. #3


    Mike Pfeiffer Guest

    RE: Does property/Attribure exist?

    Try:

    [adsi]::Exists("LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World")

    "Tim Munro" wrote:

    > hi all,
    > I'm trying to find how to determine if a property or attribute exists in
    > an AD object. Specifically the accountexpirationdate. If I just look for and
    > it's not there, and exception is thrown.
    >
    > Quick example:
    >
    > $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    > If ($oUser.ifAttributeexists($myAttribute)) {
    > do stuff
    > }
    >
    > Is there a way to accomplish this?
    >
    > Thanks.
    > --
    > Tim.
    >
    >
    >
    >
    >

      My System SpecsSystem Spec

  4. #4


    Mike Pfeiffer Guest

    RE: Does property/Attribure exist?

    nevermind, I just realized you were asking about the attribute and not the
    object itself...guess I should slow down and read the entire thing next time


    "Mike Pfeiffer" wrote:

    > Try:
    >
    > [adsi]::Exists("LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World")
    >
    > "Tim Munro" wrote:
    >

    > > hi all,
    > > I'm trying to find how to determine if a property or attribute exists in
    > > an AD object. Specifically the accountexpirationdate. If I just look for and
    > > it's not there, and exception is thrown.
    > >
    > > Quick example:
    > >
    > > $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    > > If ($oUser.ifAttributeexists($myAttribute)) {
    > > do stuff
    > > }
    > >
    > > Is there a way to accomplish this?
    > >
    > > Thanks.
    > > --
    > > Tim.
    > >
    > >
    > >
    > >
    > >

      My System SpecsSystem Spec

  5. #5


    Tim Munro Guest

    Re: Does property/Attribure exist?

    I'll give this a shot. Thanks Jan.

    "Jan Egil Ring" <jer@xxxxxx> wrote in message
    news:35D026F0-5EC6-4F7F-BBC5-01EA6A9749FF@xxxxxx

    > Hi!
    >
    > If using Quest`s Active Directory cmdlets are an option, you can
    > accomplish this by using this one-liner:
    > Get-QADUser | Where-Object {$_.accountexpires -ne $null}
    >
    > You can get Quest`s AD cmlets from here:
    > http://www.quest.com/activeroles-server/arms.aspx
    >
    > --
    > Jan Egil Ring
    > ---------------------
    > http://janegilring.wordpress.com
    > http://powershellug.ning.com
    >
    > "Tim Munro" <Excelsior@xxxxxx> wrote in message
    > news:uEn4yUoJKHA.1252@xxxxxx

    >> hi all,
    >> I'm trying to find how to determine if a property or attribute exists
    >> in an AD object. Specifically the accountexpirationdate. If I just look
    >> for and it's not there, and exception is thrown.
    >>
    >> Quick example:
    >>
    >> $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    >> If ($oUser.ifAttributeexists($myAttribute)) {
    >> do stuff
    >> }
    >>
    >> Is there a way to accomplish this?
    >>
    >> Thanks.
    >> --
    >> Tim.
    >>
    >>
    >>
    >>


      My System SpecsSystem Spec

  6. #6


    Tim Munro Guest

    Re: Does property/Attribure exist?

    Thanks for trying Mike. I like the [adsi]::Exists though. How can I find out
    what other methods are available through the [adsi] provider?

    "Mike Pfeiffer" <MikePfeiffer@xxxxxx> wrote in message
    news:AB62A9AE-7A39-4311-BAC9-2D6BC710C69D@xxxxxx

    > nevermind, I just realized you were asking about the attribute and not the
    > object itself...guess I should slow down and read the entire thing next
    > time
    >
    >
    > "Mike Pfeiffer" wrote:
    >

    >> Try:
    >>
    >> [adsi]::Exists("LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World")
    >>
    >> "Tim Munro" wrote:
    >>

    >> > hi all,
    >> > I'm trying to find how to determine if a property or attribute
    >> > exists in
    >> > an AD object. Specifically the accountexpirationdate. If I just look
    >> > for and
    >> > it's not there, and exception is thrown.
    >> >
    >> > Quick example:
    >> >
    >> > $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    >> > If ($oUser.ifAttributeexists($myAttribute)) {
    >> > do stuff
    >> > }
    >> >
    >> > Is there a way to accomplish this?
    >> >
    >> > Thanks.
    >> > --
    >> > Tim.
    >> >
    >> >
    >> >
    >> >
    >> >


      My System SpecsSystem Spec

  7. #7


    Mike Pfeiffer Guest

    Re: Does property/Attribure exist?

    I think exists() is probably the only static method of any use, but you can
    use get-member:

    [adsi] | get-member -static

    And for instance members:

    $user = [adsi]"LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    $user | get-member

    The above will give you an adapted view, to view the raw object:

    $user.psbase | get-member

    This may be of some help:
    http://blogs.technet.com/benp/archiv...owershell.aspx

    The quest cmdlets are alot easier to work with and will save you some time
    if you have the option to use them.

    "Tim Munro" wrote:

    > Thanks for trying Mike. I like the [adsi]::Exists though. How can I find out
    > what other methods are available through the [adsi] provider?
    >
    > "Mike Pfeiffer" <MikePfeiffer@xxxxxx> wrote in message
    > news:AB62A9AE-7A39-4311-BAC9-2D6BC710C69D@xxxxxx

    > > nevermind, I just realized you were asking about the attribute and not the
    > > object itself...guess I should slow down and read the entire thing next
    > > time
    > >
    > >
    > > "Mike Pfeiffer" wrote:
    > >

    > >> Try:
    > >>
    > >> [adsi]::Exists("LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World")
    > >>
    > >> "Tim Munro" wrote:
    > >>
    > >> > hi all,
    > >> > I'm trying to find how to determine if a property or attribute
    > >> > exists in
    > >> > an AD object. Specifically the accountexpirationdate. If I just look
    > >> > for and
    > >> > it's not there, and exception is thrown.
    > >> >
    > >> > Quick example:
    > >> >
    > >> > $oUser = [adsi] "LDAP://CN=Joe User,OU=HisOU,DC=Domain,DC=World"
    > >> > If ($oUser.ifAttributeexists($myAttribute)) {
    > >> > do stuff
    > >> > }
    > >> >
    > >> > Is there a way to accomplish this?
    > >> >
    > >> > Thanks.
    > >> > --
    > >> > Tim.
    > >> >
    > >> >
    > >> >
    > >> >
    > >> >
    >
    >
    >

      My System SpecsSystem Spec

Does property/Attribure exist?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Does this exist? cwatson71 Network & Sharing 1 10 Dec 2008
Set Focus To Specific Property In Property Grid Derek Hart .NET General 10 06 Oct 2008
Use my custom TypeDescriptor to obtains default Value on property inXAML Property Editor of Visual Studio 2008 azerty Avalon 0 14 Apr 2008
DNS Name does not exist Bill Vista account administration 1 07 Dec 2006
OE7 Do You Exist? Grumpy Vista General 3 03 Jun 2006