?
Solved

Pull the terminalservicesinitialprogram property value from AD

Posted on 2013-06-13
2
Medium Priority
?
832 Views
Last Modified: 2013-06-14
Hello,

I need to pull the ctxinitialprogram or terminalservicesinitialprogram property from AD for all users in all OUs.  I have a script from Josh Muehe that goes through AD and pulls different properties for users and dumps them in a .csv.  When I try to add the above property the script doesn't fail but it just runs indefinitely and never populates the .csv beyond the title row.  I have tried modifying the script below with both the ctxinitialprogram property in the query as well at the terminalservicesinitialprogram property.  Neither work.  I have included both scripts that I am running.   The shorter one pulls the property successfully for one user.  The longer one works great until I try to pull the initial program property.

Any help would be greatly appreciated as I have exhausted what little knowledge I have of scripting and my google chi is apparently inadequate to find a solution.

'Query again so we can report other fields
strBase = "<LDAP://" & strAD1 & "/" & OUFilter & DomainContainer & ">"
strAttributes = "sAMAccountName,cn,givenName,sn,distinguishedName,objectCategory,mail,description, createtimestamp, ctxinitialprogram"
strQuery = strBase & ";" & ldapFltr & ";" & strAttributes & ";subtree"

msgbox "strquery = " & strquery

adoCommand.CommandText = strQuery
Set adoRecordset = adoCommand.Execute

' Write compiled data to the log
objLogFile.WriteLine "Display Name, Logon Name, First Name, Last Name, E-Mail, Last Logon, Category, distinguishedName, OU, Description, created timestamp, Initial Program"

While NOT adoRecordset.EOF
      strObjectCategory = Mid(adoRecordset.Fields("objectCategory").value, 4, InStr(adoRecordset.Fields("objectCategory").value,",")-4)
      
        outputarray = split(adoRecordset.Fields("distinguishedName").Value, ",")

      for each x in outputarray
            if ucase(left(x, 3)) = "OU=" then
                           strOU = (right(x, (len(x)-3)))
                           Exit For            
            end if
      next

      arrDesc = adoRecordset.Fields("description").Value
           If IsNull(arrDesc) Then
               strDesc = ""
           Else
               strDesc = arrDesc(0)
          End If
 
      objLogFile.WriteLine CHR(34) & adoRecordset.Fields("cn").Value &  CHR(34) & "," &  CHR(34) & adoRecordset.Fields("sAMAccountName").Value & CHR(34) & "," _
            & CHR(34) & adoRecordset.Fields("givenName").Value & CHR(34) & "," & CHR(34) & adoRecordset.Fields("sn").Value & CHR(34) & "," & CHR(34) & adoRecordset.Fields("mail").Value & CHR(34) & "," _
            & CHR(34) & objList.Item(adoRecordset.Fields("sAMAccountName").Value) & CHR(34) & "," & CHR(34) & strObjectCategory & CHR(34) _
            & "," & CHR(34) & adoRecordset.Fields("distinguishedName").Value & CHR(34) & "," & CHR(34) & strOU & CHR(34) & "," & CHR(34) & strDesc & CHR(34) & "," & CHR(34) & adoRecordset.Fields("createtimestamp").Value & CHR(34)
      adoRecordset.MoveNext
Wend
initprogram.vbs
Last-Login-Report.vbs
0
Comment
Question by:telcor736
2 Comments
 
LVL 16

Accepted Solution

by:
cantoris earned 2000 total points
ID: 39246810
I think the issue is that the value you want is stored *within* an attribute called userParameters and so can't be got at with a simple query; only by binding to each user object in turn and using a "property method" as your shorter script does.
Look at the accepted answer here:
http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/9426bb08-0a47-4a4f-94b3-7d4beb5c8deb

Under Server2008, there is the suggestion that there is a directly readable LDAP attribute called  msTSInitialProgram.  Try that in your attribute list and see if it works.
0
 

Author Comment

by:telcor736
ID: 39247604
Thanks!  With a little modification that script in the link worked great!  The mstsintialprogram property does not work, FYI.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

OfficeMate Freezes on login or does not load after login credentials are input.
Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question