[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

Finding users that have TSPROFILES

I am looking to find a script that can be run that will tell me which users in a domain has a TSPROFILE in Active Directory. I sit possible that this script could also find whether the user has a standard profile?

Any suggestions or if anyone already has a script created and could sent it me would be appreciated
0
MartynLawson
Asked:
MartynLawson
  • 3
  • 2
1 Solution
 
Mike KlineCommented:
I can quickly help with request #2 (for standard profile)
I use adfind
http://www.joeware.net/freetools/tools/adfind/index.htm
adfind -default -f "&(objectcategory=person)(objectclass=user)(profilepath=*)" samaccountname
The reason it doesn't work for TerminalServicesProfilePath is because that attribute doesn't exist in AD (odd I know)
I'll let you know if I find a script for that.
Thanks
Mike
0
 
HubasanCommented:
Here you go:
This script will log both profiles (Regular user profile and Terminal Services, If they exist) in the log file that will be placed in the same folder where the script is executed from. Log file will be a CSV file that can be imported to excel for further manipulation.
Information in the log file will have the following order:
UserID,Real Name,Profile Path,TS Profile Path


On Error Resume Next
 
Set oWS = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
 
Const ADS_SCOPE_SUBTREE = 2
 
'Setup a logfile
sScriptName = WScript.ScriptName
sScriptPath = WScript.ScriptFullName
sLog = Replace(sScriptName, ".vbs",".csv")
sLogFile = Replace(sScriptPath, sScriptName, sLog)
Set oLogFile = oFS.CreateTextFile(sLogFile,True)
 
'Write starting point of the log
oLogfile.WriteLine "UserID,Real Name,Profile Path,TS Profile Path"
 
Set oRootDSE = GetObject("LDAP://rootDSE")
sADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
Set oDomain = GetObject(sADsPath)
 
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand =   CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
 
oCommand.Properties("Page Size") = 1000
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
oCommand.CommandText = _
    "SELECT Name,ADsPath,sAMAccountName FROM '" & sADsPath &"' WHERE objectCategory='user'"  
Set oRecordSet = oCommand.Execute
oRecordSet.MoveFirst
 
Do Until oRecordSet.EOF
	sUserADPath = oRecordSet.Fields("AdsPath").Value
	Set oUser = GetObject(sUserADPath)
	sUserID = oRecordSet.Fields("sAMAccountName").Value
	sRealName = oUser.givenName & " " & oUser.sn	
	sProfilePath = oUser.Get("profilePath")
	sTSProfilePath = oUser.TerminalServicesProfilePath
	
	oLogFile.WriteLine sUserID & "," & sRealName & "," & sProfilePath & "," & sTSProfilePath
	oRecordSet.MoveNext
Loop

Open in new window

0
 
HubasanCommented:
Khm...sorry there was a small mistake in the previous script that would produce some duplicate results.
Here is the fixed version that will give you proper results:
On Error Resume Next
 
Set oWS = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
 
Const ADS_SCOPE_SUBTREE = 2
 
'Setup a logfile
sScriptName = WScript.ScriptName
sScriptPath = WScript.ScriptFullName
sLog = Replace(sScriptName, ".vbs",".csv")
sLogFile = Replace(sScriptPath, sScriptName, sLog)
Set oLogFile = oFS.CreateTextFile(sLogFile,True)
 
'Write starting point of the log
oLogfile.WriteLine "UserID,Real Name,Profile Path,TS Profile Path"
 
Set oRootDSE = GetObject("LDAP://rootDSE")
sADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
Set oDomain = GetObject(sADsPath)
 
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand =   CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
 
oCommand.Properties("Page Size") = 1000
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
oCommand.CommandText = _
    "SELECT Name,ADsPath,sAMAccountName FROM '" & sADsPath &"' WHERE objectCategory='user'"  
Set oRecordSet = oCommand.Execute
oRecordSet.MoveFirst
 
Do Until oRecordSet.EOF
	sUserADPath = Empty
	oUser = Nothing
	sUserID = Empty
	sRealName = Empty
	sProfilePath = Empty
	sTSProfilePath = Empty
	sUserADPath = oRecordSet.Fields("AdsPath").Value
	Set oUser = GetObject(sUserADPath)
	sUserID = oRecordSet.Fields("sAMAccountName").Value
	sRealName = oUser.givenName & " " & oUser.sn	
	sProfilePath = oUser.Get("profilePath")
	sTSProfilePath = oUser.TerminalServicesProfilePath
	
	oLogFile.WriteLine sUserID & "," & sRealName & "," & sProfilePath & "," & sTSProfilePath
	oRecordSet.MoveNext
Loop

Open in new window

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
MartynLawsonAuthor Commented:
Thanks very much for your help. The script has worked great.

Is it possible to add something to this script so that it lists what OU the user is currently residing in?
0
 
HubasanCommented:
Sure. I can give you the exact AD path of the users container that will tell you what OU they are in. We can list that as one of the parameters for the user account.

However there is a something else we will have to do. We have to output this file as a .tsv (Tab separated value) from now on, since ADsPath parameter we want to add to the script, is separated by coma's so it would not come out right if we output it as CSV.
So when you import this into excel just chose TAB separated and you should be fine.

Here try this:
On Error Resume Next
 
Set oWS = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
 
Const ADS_SCOPE_SUBTREE = 2
 
'Setup a logfile
sScriptName = WScript.ScriptName
sScriptPath = WScript.ScriptFullName
sLog = Replace(sScriptName, ".vbs",".tsv")
sLogFile = Replace(sScriptPath, sScriptName, sLog)
Set oLogFile = oFS.CreateTextFile(sLogFile,True)
 
'Write starting point of the log
oLogfile.WriteLine "UserID" & vbTab & "Real Name" & vbTab &_
"Profile Path" & vbTab & "TS Profile Path" & vbTab & "ADsPath"
 
Set oRootDSE = GetObject("LDAP://rootDSE")
sADsPath = "LDAP://" & oRootDSE.Get("defaultNamingContext")
Set oDomain = GetObject(sADsPath)
 
Set oConnection = CreateObject("ADODB.Connection")
Set oCommand =   CreateObject("ADODB.Command")
oConnection.Provider = "ADsDSOObject"
oConnection.Open "Active Directory Provider"
Set oCommand.ActiveConnection = oConnection
 
oCommand.Properties("Page Size") = 1000
oCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
 
oCommand.CommandText = _
    "SELECT Name,ADsPath,sAMAccountName FROM '" & sADsPath &"' WHERE objectCategory='user'"  
Set oRecordSet = oCommand.Execute
oRecordSet.MoveFirst
 
Do Until oRecordSet.EOF
	sUserADPath = Empty
	oUser = Nothing
	sUserID = Empty
	sRealName = Empty
	sProfilePath = Empty
	sTSProfilePath = Empty
	sUserADPath = oRecordSet.Fields("AdsPath").Value
	Set oUser = GetObject(sUserADPath)
	sUserID = oRecordSet.Fields("sAMAccountName").Value
	sRealName = oUser.givenName & " " & oUser.sn	
	sProfilePath = oUser.Get("profilePath")
	sTSProfilePath = oUser.TerminalServicesProfilePath
	
	oLogFile.WriteLine sUserID & vbtab & sRealName & vbtab &_
	sProfilePath & vbtab & sTSProfilePath & vbtab & Replace(sUserADPath, "LDAP://","")
	oRecordSet.MoveNext
Loop

Open in new window

0
 
MartynLawsonAuthor Commented:
That has worked great

Thanks very much for your help :)
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now