Windows Vista Forums

Convert Active Directory IADSLargeInteger

  1. #1


    Jobbsy Guest

    Convert Active Directory IADSLargeInteger

    I thought this was going to be easy after finally getting my hands on the AD
    User
    pwdlastset values - I am now unable to convert them - I have tried
    using the System.DirectoryServices.DirectorySearcher method described in the
    following url

    http://bsonposh.com/modules/wordpress/?p=30


    but am unable to get past the first hurdle no matter what i try I receive
    the following
    error:

    + param([string]$LdapPath,[string]$Attribute = $(throw <<<< "Attribute
    Required"),[string]$server,[switch]$date)

    any help would be much appreciated as yet again i have spent far too much
    time trying to overcome this - I have done the conversion before no problem
    in VBScript - again I am reluctant to install Quest cmdlets as they are
    labelled as 'RC' and this script will (if I ever finish it!) be running on
    Prod DCs

    I have also used tried the following with no success:

    http://weblogs.asp.net/adweigert/arc...tem-int64.aspx
    --
    jobbsy@xxxxxx

      My System SpecsSystem Spec

  2. #2


    Brandon Shell [MVP] Guest

    Re: Convert Active Directory IADSLargeInteger

    It is not a string. What are you using $attribute for?

    Hello Jobbsy,

    > I thought this was going to be easy after finally getting my hands on
    > the AD
    > User
    > pwdlastset values - I am now unable to convert them - I have tried
    > using the System.DirectoryServices.DirectorySearcher method described
    > in the
    > following url
    > http://bsonposh.com/modules/wordpress/?p=30
    >
    > but am unable to get past the first hurdle no matter what i try I
    > receive the following error:
    >
    > + param([string]$LdapPath,[string]$Attribute = $(throw <<<<
    > "Attribute Required"),[string]$server,[switch]$date)
    >
    > any help would be much appreciated as yet again i have spent far too
    > much time trying to overcome this - I have done the conversion before
    > no problem in VBScript - again I am reluctant to install Quest cmdlets
    > as they are labelled as 'RC' and this script will (if I ever finish
    > it!) be running on Prod DCs
    >
    > I have also used tried the following with no success:
    >
    > http://weblogs.asp.net/adweigert/arc...rshell-convert
    > -active-directory-iadslargeinteger-to-system-int64.aspx
    >


      My System SpecsSystem Spec

  3. #3


    Gaurhoth Guest

    Re: Convert Active Directory IADSLargeInteger

    Using adweigert's ConvertADSLargeInteger should work just fine. I use it
    all of the time. Here's an example of it's usage:

    PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    Petrelli,cn=users,dc=testlab,dc=com"
    PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    $user.pwdlastset.value))

    Saturday, October 27, 2007 8:17:30 PM

    If there is something else you are having a problem with, post more of
    the function or script and maybe we can troubleshoot it.

    Gaurhoth



    Jobbsy wrote:

    > I thought this was going to be easy after finally getting my hands on the AD
    > User
    > pwdlastset values - I am now unable to convert them - I have tried
    > using the System.DirectoryServices.DirectorySearcher method described in the
    > following url
    >
    > http://bsonposh.com/modules/wordpress/?p=30
    >
    >
    > but am unable to get past the first hurdle no matter what i try I receive
    > the following
    > error:
    >
    > + param([string]$LdapPath,[string]$Attribute = $(throw <<<< "Attribute
    > Required"),[string]$server,[switch]$date)
    >
    > any help would be much appreciated as yet again i have spent far too much
    > time trying to overcome this - I have done the conversion before no problem
    > in VBScript - again I am reluctant to install Quest cmdlets as they are
    > labelled as 'RC' and this script will (if I ever finish it!) be running on
    > Prod DCs
    >
    > I have also used tried the following with no success:
    >
    > http://weblogs.asp.net/adweigert/arc...tem-int64.aspx
    >

      My System SpecsSystem Spec

  4. #4


    Brandon Shell [MVP] Guest

    Re: Convert Active Directory IADSLargeInteger

    I dont think converting the value is the problem... it looks like using the
    value is the problem.

    As I ask before... what do you use $attribute for?

    Hello Gaurhoth,

    > Using adweigert's ConvertADSLargeInteger should work just fine. I use
    > it all of the time. Here's an example of it's usage:
    >
    > PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    > Petrelli,cn=users,dc=testlab,dc=com"
    > PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > $user.pwdlastset.value))
    > Saturday, October 27, 2007 8:17:30 PM
    >
    > If there is something else you are having a problem with, post more of
    > the function or script and maybe we can troubleshoot it.
    >
    > Gaurhoth
    >
    > Jobbsy wrote:
    >

    >> I thought this was going to be easy after finally getting my hands on
    >> the AD
    >> User
    >> pwdlastset values - I am now unable to convert them - I have tried
    >> using the System.DirectoryServices.DirectorySearcher method described
    >> in the
    >> following url
    >> http://bsonposh.com/modules/wordpress/?p=30
    >>
    >> but am unable to get past the first hurdle no matter what i try I
    >> receive the following error:
    >>
    >> + param([string]$LdapPath,[string]$Attribute = $(throw <<<<
    >> "Attribute Required"),[string]$server,[switch]$date)
    >>
    >> any help would be much appreciated as yet again i have spent far too
    >> much time trying to overcome this - I have done the conversion before
    >> no problem in VBScript - again I am reluctant to install Quest
    >> cmdlets as they are labelled as 'RC' and this script will (if I ever
    >> finish it!) be running on Prod DCs
    >>
    >> I have also used tried the following with no success:
    >>
    >> http://weblogs.asp.net/adweigert/arc...ershell-conver
    >> t-active-directory-iadslargeinteger-to-system-int64.aspx
    >>


      My System SpecsSystem Spec

  5. #5


    Jobbsy Guest

    Re: Convert Active Directory IADSLargeInteger

    Thanks Gaurhoth - what I needed was an example of it's use, however I still
    am unable to see it working successfully, so excuse me for my ignorance if
    there is an elementary mistake as i am a beginner but this is the code I am
    trying to use it in, and like before with adweigert's ConvertADSLargeInteger
    after seeing your example and trying to fit it to my code I still receive
    exactly the same error as before - below the error is a sample of my code:

    Exception calling "InvokeMember" with "5" argument(s): "Method
    'System.Int64.HighPart' not found."
    At 45 char:56
    + $highPart = $adsLargeInteger.GetType().InvokeMember( <<<< "HighPart",
    [System.Reflection.BindingFlags]::GetProper
    ty, $null, $adsLargeInteger, $null)
    Exception calling "InvokeMember" with "5" argument(s): "Method
    'System.Int64.LowPart' not found."

    ###########Sample############

    foreach ($person in $adobj)
    {
    $prop=$person.psbase.properties
    $i++

    $1stField = "$($prop.name)" + ","
    $2ndField = "$($prop.memberof)" + ","
    $3rdField = "$($prop.whencreated)" + ","

    #$4th Field - Password Last Set
    #----------------------------------------------------------
    #Convert the large Integer format into a readable date

    $LI = [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    $($prop.pwdlastset)))
    $4thField = "$LI" + ","

    $strOutputString = "$1stField" + "$2ndField" + "$3rdField" + "$4thField"

    ######################################################

    --
    jobbsy@xxxxxx


    "Gaurhoth" wrote:

    > Using adweigert's ConvertADSLargeInteger should work just fine. I use it
    > all of the time. Here's an example of it's usage:
    >
    > PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    > Petrelli,cn=users,dc=testlab,dc=com"
    > PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > $user.pwdlastset.value))
    >
    > Saturday, October 27, 2007 8:17:30 PM
    >
    > If there is something else you are having a problem with, post more of
    > the function or script and maybe we can troubleshoot it.
    >
    > Gaurhoth
    >
    >
    >
    > Jobbsy wrote:

    > > I thought this was going to be easy after finally getting my hands on the AD
    > > User
    > > pwdlastset values - I am now unable to convert them - I have tried
    > > using the System.DirectoryServices.DirectorySearcher method described in the
    > > following url
    > >
    > > http://bsonposh.com/modules/wordpress/?p=30
    > >
    > >
    > > but am unable to get past the first hurdle no matter what i try I receive
    > > the following
    > > error:
    > >
    > > + param([string]$LdapPath,[string]$Attribute = $(throw <<<< "Attribute
    > > Required"),[string]$server,[switch]$date)
    > >
    > > any help would be much appreciated as yet again i have spent far too much
    > > time trying to overcome this - I have done the conversion before no problem
    > > in VBScript - again I am reluctant to install Quest cmdlets as they are
    > > labelled as 'RC' and this script will (if I ever finish it!) be running on
    > > Prod DCs
    > >
    > > I have also used tried the following with no success:
    > >
    > > http://weblogs.asp.net/adweigert/arc...tem-int64.aspx
    > >
    >

      My System SpecsSystem Spec

  6. #6


    Brandon Shell [MVP] Guest

    Re: Convert Active Directory IADSLargeInteger

    Your having problems parsing the date? You will notice you should should
    use Parse not fromfiletimeUTC

    I have a -date parameter on my Get-iADSLargeIntFromSearcher function

    function Get-iADSLargeIntFromSearcher{
    param([string]$LdapPath,[string]$attribute = $(throw "Attribute Required"),[string]$server,[switch]$date)
    if($server){$de = [ADSI]"LDAP://$server/$LdapPath"}
    else{$de = [ADSI]"LDAP://$LdapPath"}
    $return = new-object system.DirectoryServices.DirectorySearcher($de)
    $value = ($return.findone()).properties[$attribute.ToLower()]
    if( $date)
    {
    [datetime]::FromFileTime([int64]::Parse($value))
    }
    else
    {
    $value
    }
    }

    # This should put the Date in $LI
    $LI = Get-iADSLargeIntFromSearcher $prop.distinguishName "pwdLastSet" -date

    Hello Jobbsy,

    > Thanks Gaurhoth - what I needed was an example of it's use, however I
    > still am unable to see it working successfully, so excuse me for my
    > ignorance if there is an elementary mistake as i am a beginner but
    > this is the code I am trying to use it in, and like before with
    > adweigert's ConvertADSLargeInteger after seeing your example and
    > trying to fit it to my code I still receive exactly the same error as
    > before - below the error is a sample of my code:
    >
    > Exception calling "InvokeMember" with "5" argument(s): "Method
    > 'System.Int64.HighPart' not found."
    > At 45 char:56
    > + $highPart = $adsLargeInteger.GetType().InvokeMember( <<<<
    > "HighPart",
    > [System.Reflection.BindingFlags]::GetProper
    > ty, $null, $adsLargeInteger, $null)
    > Exception calling "InvokeMember" with "5" argument(s): "Method
    > 'System.Int64.LowPart' not found."
    > ###########Sample############
    >
    > foreach ($person in $adobj)
    > {
    > $prop=$person.psbase.properties
    > $i++
    > $1stField = "$($prop.name)" + ","
    > $2ndField = "$($prop.memberof)" + ","
    > $3rdField = "$($prop.whencreated)" + ","
    > #$4th Field - Password Last Set
    > #---------------------------------------------------------- #Convert
    > the large Integer format into a readable date
    >
    > $LI = [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > $($prop.pwdlastset)))
    > $4thField = "$LI" + ","
    > $strOutputString = "$1stField" + "$2ndField" + "$3rdField" +
    > "$4thField"
    >
    > ######################################################
    >
    > "Gaurhoth" wrote:
    >

    >> Using adweigert's ConvertADSLargeInteger should work just fine. I use
    >> it all of the time. Here's an example of it's usage:
    >>
    >> PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    >> Petrelli,cn=users,dc=testlab,dc=com"
    >> PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    >> $user.pwdlastset.value))
    >> Saturday, October 27, 2007 8:17:30 PM
    >>
    >> If there is something else you are having a problem with, post more
    >> of the function or script and maybe we can troubleshoot it.
    >>
    >> Gaurhoth
    >>
    >> Jobbsy wrote:
    >>

    >>> I thought this was going to be easy after finally getting my hands
    >>> on the AD
    >>> User
    >>> pwdlastset values - I am now unable to convert them - I have tried
    >>> using the System.DirectoryServices.DirectorySearcher method
    >>> described in the
    >>> following url
    >>> http://bsonposh.com/modules/wordpress/?p=30
    >>>
    >>> but am unable to get past the first hurdle no matter what i try I
    >>> receive the following error:
    >>>
    >>> + param([string]$LdapPath,[string]$Attribute = $(throw <<<<
    >>> "Attribute Required"),[string]$server,[switch]$date)
    >>>
    >>> any help would be much appreciated as yet again i have spent far too
    >>> much time trying to overcome this - I have done the conversion
    >>> before no problem in VBScript - again I am reluctant to install
    >>> Quest cmdlets as they are labelled as 'RC' and this script will (if
    >>> I ever finish it!) be running on Prod DCs
    >>>
    >>> I have also used tried the following with no success:
    >>>
    >>> http://weblogs.asp.net/adweigert/arc...wershell-conve
    >>> rt-active-directory-iadslargeinteger-to-system-int64.aspx
    >>>


      My System SpecsSystem Spec

  7. #7


    Jobbsy Guest

    Re: Convert Active Directory IADSLargeInteger

    Thanks Brandon but I think I'm going to need a little more spoon feeding on
    this one:

    Exception calling "FindOne" with "0" argument(s): "Unknown error (0x80005000)"
    At C:\PS1Scripts\ActiveDirectory.ps1:65 char:30
    + $value = ($return.findone( <<<< )).properties[$attribute.ToLower()]
    Exception calling "Parse" with "1" argument(s): "Input string was not in a
    correct format."
    At 68 char:48
    + [datetime]::FromFileTime([int64]::Parse( <<<< $value))

    --
    jobbsy@xxxxxx


    "Brandon Shell [MVP]" wrote:

    > Your having problems parsing the date? You will notice you should should
    > use Parse not fromfiletimeUTC
    >
    > I have a -date parameter on my Get-iADSLargeIntFromSearcher function
    >
    > function Get-iADSLargeIntFromSearcher{
    > param([string]$LdapPath,[string]$attribute = $(throw "Attribute Required"),[string]$server,[switch]$date)
    > if($server){$de = [ADSI]"LDAP://$server/$LdapPath"}
    > else{$de = [ADSI]"LDAP://$LdapPath"}
    > $return = new-object system.DirectoryServices.DirectorySearcher($de)
    > $value = ($return.findone()).properties[$attribute.ToLower()]
    > if( $date)
    > {
    > [datetime]::FromFileTime([int64]::Parse($value))
    > }
    > else
    > {
    > $value
    > }
    > }
    >
    > # This should put the Date in $LI
    > $LI = Get-iADSLargeIntFromSearcher $prop.distinguishName "pwdLastSet" -date
    >
    > Hello Jobbsy,
    >

    > > Thanks Gaurhoth - what I needed was an example of it's use, however I
    > > still am unable to see it working successfully, so excuse me for my
    > > ignorance if there is an elementary mistake as i am a beginner but
    > > this is the code I am trying to use it in, and like before with
    > > adweigert's ConvertADSLargeInteger after seeing your example and
    > > trying to fit it to my code I still receive exactly the same error as
    > > before - below the error is a sample of my code:
    > >
    > > Exception calling "InvokeMember" with "5" argument(s): "Method
    > > 'System.Int64.HighPart' not found."
    > > At 45 char:56
    > > + $highPart = $adsLargeInteger.GetType().InvokeMember( <<<<
    > > "HighPart",
    > > [System.Reflection.BindingFlags]::GetProper
    > > ty, $null, $adsLargeInteger, $null)
    > > Exception calling "InvokeMember" with "5" argument(s): "Method
    > > 'System.Int64.LowPart' not found."
    > > ###########Sample############
    > >
    > > foreach ($person in $adobj)
    > > {
    > > $prop=$person.psbase.properties
    > > $i++
    > > $1stField = "$($prop.name)" + ","
    > > $2ndField = "$($prop.memberof)" + ","
    > > $3rdField = "$($prop.whencreated)" + ","
    > > #$4th Field - Password Last Set
    > > #---------------------------------------------------------- #Convert
    > > the large Integer format into a readable date
    > >
    > > $LI = [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > > $($prop.pwdlastset)))
    > > $4thField = "$LI" + ","
    > > $strOutputString = "$1stField" + "$2ndField" + "$3rdField" +
    > > "$4thField"
    > >
    > > ######################################################
    > >
    > > "Gaurhoth" wrote:
    > >

    > >> Using adweigert's ConvertADSLargeInteger should work just fine. I use
    > >> it all of the time. Here's an example of it's usage:
    > >>
    > >> PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    > >> Petrelli,cn=users,dc=testlab,dc=com"
    > >> PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > >> $user.pwdlastset.value))
    > >> Saturday, October 27, 2007 8:17:30 PM
    > >>
    > >> If there is something else you are having a problem with, post more
    > >> of the function or script and maybe we can troubleshoot it.
    > >>
    > >> Gaurhoth
    > >>
    > >> Jobbsy wrote:
    > >>
    > >>> I thought this was going to be easy after finally getting my hands
    > >>> on the AD
    > >>> User
    > >>> pwdlastset values - I am now unable to convert them - I have tried
    > >>> using the System.DirectoryServices.DirectorySearcher method
    > >>> described in the
    > >>> following url
    > >>> http://bsonposh.com/modules/wordpress/?p=30
    > >>>
    > >>> but am unable to get past the first hurdle no matter what i try I
    > >>> receive the following error:
    > >>>
    > >>> + param([string]$LdapPath,[string]$Attribute = $(throw <<<<
    > >>> "Attribute Required"),[string]$server,[switch]$date)
    > >>>
    > >>> any help would be much appreciated as yet again i have spent far too
    > >>> much time trying to overcome this - I have done the conversion
    > >>> before no problem in VBScript - again I am reluctant to install
    > >>> Quest cmdlets as they are labelled as 'RC' and this script will (if
    > >>> I ever finish it!) be running on Prod DCs
    > >>>
    > >>> I have also used tried the following with no success:
    > >>>
    > >>> http://weblogs.asp.net/adweigert/arc...wershell-conve
    > >>> rt-active-directory-iadslargeinteger-to-system-int64.aspx
    > >>>
    >
    >
    >

      My System SpecsSystem Spec

  8. #8


    Brandon Shell [MVP] Guest

    Re: Convert Active Directory IADSLargeInteger

    "Unknown error (0x80005000)" implies access denied. Do you have permission
    in the AD?


    Hello Jobbsy,

    > "Unknown error (0x80005000)"
    >


      My System SpecsSystem Spec

  9. #9


    Jobbsy Guest

    Re: Convert Active Directory IADSLargeInteger

    This is only a single DC Test Domain and I am running the script on the DC -
    the account I am logged on as is a member of Enterprise Admins
    --
    jobbsy@xxxxxx


    "Brandon Shell [MVP]" wrote:

    > "Unknown error (0x80005000)" implies access denied. Do you have permission
    > in the AD?
    >
    >
    > Hello Jobbsy,
    >

    > > "Unknown error (0x80005000)"
    > >
    >
    >
    >

      My System SpecsSystem Spec

  10. #10


    Jobbsy Guest

    Re: Convert Active Directory IADSLargeInteger

    Gaurhoth - thanks for your response - I'm still struggling I'm afraid I
    wondered if you could help some more?

    Here is how I'm trying to fit it to my code:

    ##########
    foreach ($person in $adobj)
    {
    $prop=$person.psbase.properties
    $i++

    $1stField = "$($prop.name)" + ","
    $2ndField = "$($prop.memberof)" + ","
    $3rdField = "$($prop.whencreated)" + ","

    #$4th Field - Password Last Set
    #----------------------------------------------------------
    #Convert the large Integer format into a readable date

    $LI = [datetime]::FromFileTimeUtc(ConvertADSLargeInteger $($prop.pwdlastset))

    $4thField = $LI

    $strOutputString = "$1stField" + "$2ndField" + "$3rdField" + "$4thField"

    ##############
    Reccuring Error for each $person:

    At 46 char:56
    + $lowPart = $adsLargeInteger.GetType().InvokeMember( <<<< "LowPart",
    [System.Reflection.BindingFlags]::GetProperty, $null, $adsLargeInteger, $null)
    Exception calling "Copy" with "5" argument(s): "Source array was not long
    enough. Check srcIndex and length, and the array's lower bounds."
    At 50 char:25
    + [System.Array]::Copy( <<<< $bytes, 0, $tmp, 4, 4)
    Exception calling "ToUInt32" with "2" argument(s): "Destination array is not
    long enough to copy all the items in the collection. Check array index and
    length."
    At 54 char:47
    + $lowPart = [System.BitConverter]::ToUInt32( <<<< $bytes, 0)
    --
    jobbsy@xxxxxx


    "Gaurhoth" wrote:

    > Using adweigert's ConvertADSLargeInteger should work just fine. I use it
    > all of the time. Here's an example of it's usage:
    >
    > PS D:\ps> $user = [ADSI]"LDAP://cn=Peter
    > Petrelli,cn=users,dc=testlab,dc=com"
    > PS D:\ps> [datetime]::FromFileTimeUtc((ConvertADSLargeInteger
    > $user.pwdlastset.value))
    >
    > Saturday, October 27, 2007 8:17:30 PM
    >
    > If there is something else you are having a problem with, post more of
    > the function or script and maybe we can troubleshoot it.
    >
    > Gaurhoth
    >
    >
    >
    > Jobbsy wrote:

    > > I thought this was going to be easy after finally getting my hands on the AD
    > > User
    > > pwdlastset values - I am now unable to convert them - I have tried
    > > using the System.DirectoryServices.DirectorySearcher method described in the
    > > following url
    > >
    > > http://bsonposh.com/modules/wordpress/?p=30
    > >
    > >
    > > but am unable to get past the first hurdle no matter what i try I receive
    > > the following
    > > error:
    > >
    > > + param([string]$LdapPath,[string]$Attribute = $(throw <<<< "Attribute
    > > Required"),[string]$server,[switch]$date)
    > >
    > > any help would be much appreciated as yet again i have spent far too much
    > > time trying to overcome this - I have done the conversion before no problem
    > > in VBScript - again I am reluctant to install Quest cmdlets as they are
    > > labelled as 'RC' and this script will (if I ever finish it!) be running on
    > > Prod DCs
    > >
    > > I have also used tried the following with no success:
    > >
    > > http://weblogs.asp.net/adweigert/arc...tem-int64.aspx
    > >
    >

      My System SpecsSystem Spec


Convert Active Directory IADSLargeInteger
Similar Threads
Thread Forum
active directory PowerShell
Active Directory Vista mail
Active Directory Vista security
Active Directory Vista networking & sharing
active directory PowerShell