Resolved Windows AD datatype Integer8 (64 bit signed numeric) field - trying to put get this field into a SQL table

Status
Not open for further replies.

AcidBurn

New member
Joined
Oct 10, 2023
Messages
2
Programming Experience
Beginner
Hi

I am querying the field LastLogonTimeStamp - its windows aAD and its datatype is Integer8 (64 bit signed numeric) field. I am doing this through SSIS - I dont want convert it to date time (just want the integer) - will dot he conversion to a date through SQL. Want to add LastLogonTimeStamp to this - can you help?

So got a c sharp script going - its as follows
Code:
#Region "Imports"
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
Imports System.DirectoryServices.AccountManagement
Imports System.DirectoryServices

#End Region

<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute()>
<CLSCompliant(False)>
Public Class ScriptMain
    Inherits UserComponent

    Dim principalContext As PrincipalContext = Nothing
    Dim principalSearcher As PrincipalSearcher = Nothing

    Public Overrides Sub PreExecute()
        principalContext = New PrincipalContext(ContextType.Domain, "IM-Firm.com")
        principalSearcher = New PrincipalSearcher(New UserPrincipal(principalContext))
        MyBase.PreExecute()
    End Sub

    Public Overrides Sub PostExecute()
        principalContext = Nothing
        principalSearcher = Nothing
        MyBase.PostExecute()
    End Sub

    Public Overrides Sub CreateNewOutputRows()

        For Each principal As Principal In principalSearcher.FindAll()

            Dim entry As DirectoryEntry = TryCast(principal.GetUnderlyingObject(), DirectoryEntry)

            With ActiveDirectoryBuffer
                .AddRow()

                If entry.Properties("givenName").Value IsNot Nothing Then
                    .FirstName = entry.Properties("givenName").Value.ToString()
                Else
                    .FirstName = "Unknown"
                End If

                If entry.Properties("sn").Value IsNot Nothing Then
                    .LastName = entry.Properties("sn").Value.ToString()
                Else
                    .LastName = "Unknown"
                End If

                If entry.Properties("Description").Value IsNot Nothing Then
                    .Description = entry.Properties("Description").Value.ToString()
                Else
                    .Description = ""
                End If

                If entry.Properties("Company").Value IsNot Nothing Then
                    .Company = entry.Properties("Company").Value.ToString()
                Else
                    .Company = ""
                End If

                If entry.Properties("Division").Value IsNot Nothing Then
                    .Division = entry.Properties("Division").Value.ToString()
                Else
                    .Division = ""
                End If

                If entry.Properties("Department").Value IsNot Nothing Then
                    .Department = entry.Properties("Department").Value.ToString()
                Else
                    .Department = ""
                End If

                If entry.Properties("Team").Value IsNot Nothing Then
                    .Team = entry.Properties("Team").Value.ToString()
                Else
                    .Team = ""
                End If

                If entry.Properties("l").Value IsNot Nothing Then
                    .l = entry.Properties("l").Value.ToString()
                Else
                    .l = ""
                End If

                If entry.Properties("Title").Value IsNot Nothing Then
                    .Title = entry.Properties("Title").Value.ToString()
                Else
                    .Title = ""
                End If

                If entry.Properties("DisplayName").Value IsNot Nothing Then
                    .DisplayName = entry.Properties("DisplayName").Value.ToString()
                Else
                    .DisplayName = ""
                End If

                If entry.Properties("PrimaryInternationalISDNNumber").Value IsNot Nothing Then
                    .PrimaryInternationalISDNNumber = entry.Properties("PrimaryInternationalISDNNumber").Value.ToString()
                Else
                    .PrimaryInternationalISDNNumber = ""
                End If

                If entry.Properties("samAccountName").Value IsNot Nothing Then
                    .SAMAccountName = entry.Properties("samAccountName").Value.ToString()
                Else
                    .SAMAccountName = "Unknown"
                End If

                If entry.Properties("userPrincipalName").Value IsNot Nothing Then
                    .UserPrincipalName = entry.Properties("userPrincipalName").Value.ToString()
                Else
                    .UserPrincipalName = ""
                End If

                If entry.Properties("userAccountControl").Value IsNot Nothing Then
                    .userAccountControl = entry.Properties("userAccountControl").Value.ToString()
                Else
                    .userAccountControl = ""
                End If

                If entry.Properties("Manager").Value IsNot Nothing Then
                    .Manager = entry.Properties("Manager").Value.ToString()
                Else
                    .Manager = ""
                End If

                If entry.Properties("Mail").Value IsNot Nothing Then
                    .Mail = entry.Properties("Mail").Value.ToString()
                Else
                    .Mail = ""
                End If


            End With

        Next
    End Sub

End Class
 
Last edited by a moderator:
That code is not C# code. That is VB.NET code. Perhaps you posted to the wrong forum?

(As an aside, in C#, code is called "code", not "script".)
 
Status
Not open for further replies.
Back
Top Bottom