wscript.echo "**********************************************************"
wscript.echo "**********************************************************"
wscript.echo "Script Name : SBC_CitrixUSerFMOMigration.vbs [SIMULATED | DOIT]"
wscript.echo "Description : "
wscript.echo " This takes VIA Userids (in users.txt) and..."
wscript.echo " a) removes the ID from each group listed in Col 1"
wscript.echo " b) adds the ID to each group listed in Col 2"
wscript.echo " of groups.txt "
wscript.echo " The parameter SIMULATED will report only"
wscript.echo " The parameter DOIT will make changes"
wscript.echo ""
wscript.echo "Files input ..."
wscript.echo " users.txt ...must contain a list of RACFIDs"
wscript.echo " groups.txt...must contain groupName1<TAB>groupName2"
wscript.echo ""
wscript.echo "Clauses..."
wscript.echo " 1/ Not Supported by members of the Directory services Team"
wscript.echo " 2/ Supplied without warranty, use at your own risk"
wscript.echo " 3/ Not fully tested, No incidents will be accepted into "
wscript.echo " the HP directory services Q as a result of this script"
wscript.echo " 4/ Nested groups has NOT been catered for"
wscript.echo "**********************************************************"
wscript.echo "**********************************************************"
set objArgs=wscript.Arguments
if objArgs.Count =1 then
param1=objArgs(0)
else
call Helpp
end if
if param1="DOIT" then
SIMULATED="FALSE"
else
SIMULATED="TRUE"
end if
wscript.echo "Script Start : " & now
tempcount=0
'Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
const ADS_SCOPE_SUBTREE = 2
Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D
Dim objConnection, objCommand, objRootDSE, strDNSDomain, strQuery
Dim objRecordSet, strDN, objGroup
dim objects_in_group
dim objargs, member_threshold, group_count, dummy, countt
dim subgroup,Str_tabs,loop_,Strdescription
dim Racfids()
dim TempUserGroup()
redim TempUserGroup(0)
dim TempUserGroupAdd()
redim TempUserGroupAdd(0)
dim groups1()
redim groups1(0)
dim groups2()
redim groups2(0)
dim strFileName
dim objFSO
dim objFile
dim strLine
dim pos
dim x
objects_in_group=0
group_count=0
subgroup=0
Str_tabs=""
wscript.echo "Loading groups..."
'load into Racfids array
strFileName = "groups.txt"
x=0
grp_errors=0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)', True, TristateFalse )
While not objFile.AtEndOfStream
strLine = UCASE(objFile.ReadLine)
x=x+1
if trim(strLine) <>"" then 'ignore blank lines
pos=instr(strLine,chr(9))
if pos >1 then 'must contain one tabsepartor not col 1
redim preserve groups1(ubound(groups1)+1)
groups1(ubound(groups1))=mid(trim(strLine),1,pos-1)
redim preserve groups2(ubound(groups2)+1)
groups2(ubound(groups2))=mid(trim(strLine),pos+1)
else
wscript.echo "Error in file format groups.txt...Please correct Line :" & x
grp_errors=grp_errors+1
end if
end if
'pos=instr(strLine,chr(9))
wend
objFile.Close
wscript.echo "Loading groups...Done"
if grp_errors>0 then
wscript.echo "Please correct groups.txt and re-run"
wscript.echo "[NB group.txt format is ... groupName1<TAB>groupName2"
wscript.quit
end if
wscript.echo "Loading RACFIDS..."
'load into Racfids array
redim Racfids(0)
strFileName = "users.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)', True, TristateFalse )
While not objFile.AtEndOfStream
strLine = UCASE(objFile.ReadLine)
if strLIne <>"" then
redim preserve Racfids(ubound(Racfids)+1)
Racfids(ubound(Racfids))=trim(strLine)
'wscript.echo "users.txt" & VBTAB & strLine
end if
wend
objFile.Close
wscript.echo "Loading RACFIDS...Done"
WSCRIPT.ECHO "==============Checking Groups.txt for existance in AD======================="
grp_errors=0
for x = 1 to UBOUND (groups1)
bit=""
wscript.echo x & VBTAB & ":" & groups1(x) & ":" & groups2(x) & ":"
bit=GetDN(groups1(x))
if bit="" then
wscript.echo "FATAL Error. AD Group does not exist whichis present in groups.txt :" & groups1(x)
grp_errors=grp_errors+1
else
groups1(x)=UCASE(bit)
end if
bit=""
bit=GetDN(groups2(x))
if bit="" then
wscript.echo "FATAL Error. AD Group does not exist whichis present in groups.txt :" & groups2(x)
grp_errors=grp_errors+1
else
groups2(x)=UCASE(bit)
end if
'StrName can be a group or user
next
if grp_errors>0 then
wscript.echo "Please correct groups.txt and re-run"
wscript.quit
end if
WSCRIPT.ECHO "============Group check Complete============================"
WSCRIPT.ECHO "======Processing users.txt==================================="
for x = 1 to UBOUND (Racfids)
UserDN=GetDN(Racfids(x))
UserDN=UCASE(UserDN)
if UserDN<>"" then
wscript.echo
wscript.echo x & VBTAB & ":" & Racfids(x) & ":" & VBTAB & UserDN
wscript.echo VBTAB & "Current group Membership [that matches col 1 in groups.txt]"
call ListUserGroups(Racfids(x))
wscript.echo VBCRLF & VBTAB & "Groups Needing removal..."
if UBOUND(TempUserGroup)=0 then wscript.echo VBTAB & "None"
call display_array(TempUserGroup) 'tempusergroup array should now be loaded and only contain groups which are in teh first column of groups1.txt
wscript.echo VBCRLF & VBTAB & "Groups Needing Adding..."
if UBOUND(TempUserGroupAdd)=0 then wscript.echo VBTAB & "None"
call display_array(TempUserGroupAdd) 'tempusergroup array should now be loaded and only contain groups which are in teh second column of groups1.txt
call process_user(UserDN) 'go thru each group in array and add and remove
else
wscript.echo x & VBTAB & ":" & Racfids(x) & ":" & VBTAB & "ERROR : NOSUCH USER"
end if
call Clear_Array(TempUserGroup) 'this is a temp working array containing users group membership listin DN form
call Clear_Array(TempUserGroupAdd) 'this is a temp working array containing users group membership listin DN form
next
WSCRIPT.ECHO "========End processing users.txt =============================="
wscript.echo "Script End : " & now
wscript.quit
function process_user(strUserDN) 'go thru each group in array and add and remove
dim p
for p= 1 to UBOUND(TempUserGroup)
wscript.echo ""
result=RemoveUserFromGroup(TempUserGroup(p),strUserDN)
if IsInGroup(strUserDN,TempUserGroup(p))="FALSE" OR SIMULATED="TRUE" then 'it it worked
result=AddUserToGroup(TempUserGroupAdd(p),strUserDN)
if IsInGroup(strUserDN,TempUserGroupAdd(p))="TRUE" OR SIMULATED="TRUE" then 'it it worked
'do nothing as all ok
else
'user not in group so backout change
result=AddUserToGroup(TempUserGroup(p),strUserDN)
if IsInGroup(strUserDN,TempUserGroup(p))="TRUE" then 'backout worked
wscript.echo VBTAB & "Backout worked, user is back in original group"
else
wscript.echo VBTAB & "ERROR : Backout did NOT work, user must be changed manually"
end if
end if
else
'wscript.echo "ERROR Unable to remove user from group"
end if
'we did not add user OK, so we must try backout
'if AddUserToGroup(TempUserGroup(p),strUserDN)="OK" then
next
end function
function ShortDN(StrName)
on error resume next
dim result,pos
result=""
pos=instr(StrName,",")
result=mid(StrName,4,pos-4)
on error goto 0
ShortDN=result
end function
function RemoveUserFromGroup(strGroupDN,strMemberDN)
dim objGroup,result
'strGroupDN = "<GroupDN>" ' e.g. cn=SalesGroup,ou=Groups,dc=rallencorp,dc=com
'strMemberDN = "<MemberDN>" ' e.g. cn=jsmith,cn=users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
RemoveUserFromGroup="FALSE"
Err.Clear
on error resume next
set objGroup = GetObject("LDAP://UKNWDAVIA811.via.novonet/" & strGroupDN)
'ldp="'LDAP://UKNWDAVIA811.via.novonet/dc=via,dc=novonet'"
' Remove a member
if SIMULATED="FALSE" then
wscript.Echo VBTAB & "Removing user from : " & ShortDN(strGroupDN)
objGroup.Remove("LDAP://" & strMemberDN)
result=Err.Number
if result =-2147016651 then 'user already removed
RemoveUserFromGroup="OK"
wscript.Echo VBTAB & "Warning : User already removed from group : " & ShortDN(strGroupDN)
else
if result<>0 then
wscript.Echo VBTAB & "ERROR : " & Err.Number & " removing user from group : " & ShortDN(strGroupDN)
else
RemoveUserFromGroup="OK"
end if
end if
else
wscript.Echo VBTAB & "Simulated : Removing user from : " & ShortDN(strGroupDN)
end if
on error goto 0
end function
function AddUserToGroup(strGroupDN,strMemberDN)
dim objGroup
'strGroupDN = "<GroupDN>" ' e.g. cn=SalesGroup,ou=Groups,dc=rallencorp,dc=com
'strMemberDN = "<MemberDN>" ' e.g. cn=jsmith,cn=users,dc=rallencorp,dc=com
' ------ END CONFIGURATION ---------
AddUserToGroup="FALSE"
Err.Clear
on error resume next
set objGroup = GetObject("LDAP://UKNWDAVIA811.via.novonet/" & strGroupDN)
' Remove a member
if SIMULATED="FALSE" then
wscript.Echo VBTAB & "Adding user to group : " & ShortDN(strGroupDN)
objGroup.Add("LDAP://" & strMemberDN)
result=Err.Number
if result=-2147019886 then 'user already in group
AddUserToGroup="OK"
wscript.Echo VBTAB & "Warning : User already in group : " & ShortDN(strGroupDN)
else
if result<>0 then
wscript.Echo VBTAB & "ERROR : " & Err.Number & " Adding user to group : " & ShortDN(strGroupDN)
'wscript.Echo "Removing ...:" & strMemberDN
'remove_count=remove_count+1
else
AddUserToGroup="OK"
end if
end if
else
wscript.Echo VBTAB & "Simulated : Adding user to group : " & ShortDN(strGroupDN)
end if
on error goto 0
end function
function Get_Domain() 'gets the default domain name
Set objDomain = getObject("LDAP://rootDse")
objDC = objDomain.Get("DefaultNamingContext")
DC=mid(objDC,1,instr(objDC,",")-1)
Get_Domain=mid(DC,4)
end function
'wscript.echo "Start Script..."
'StrComputer="."
'set ObjUser=GetObject("WinNT://via.novonet/fred,user")
'set ObjGroup=GetObject("WinNT://" & StrComputer & "/Administrators,Group")
'ObjGroup.Add (ObjUser.ADsPath)
'wscript.echo "End Script..."
function local_computer_name
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings
Wscript.Echo "System Name: " & objComputer.Name
local_computer_name=objComputer.Name
Next
end function
function display_array(Arr)
wscript.Echo
'wscript.Echo "Array..."
for loop_ =1 to UBOUND(arr)
wscript.Echo VBTAB & loop_ & TAB & ":" & arr(loop_) &":"
next
'wscript.Echo "Array end."
wscript.Echo
end function
function get_local_admins(strComputer)
dim strDomain, objWshNetwork, strGroupSID, strGroupName, objGroup, objMember
dim bit, pos, strObject
Set objWshNetwork = CreateObject("WScript.Network")
'strComputer = objWshNetwork.ComputerName
strGroupSID = "S-1-5-32-544" ' Well Known SID of the Administrators group
' Obtain the group name based on well know SID
strGroupName = GetGroupName(strComputer, strGroupSID)
' Connect to the group
Err.Clear
on error resume next
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroupName & ",group")
if Err.Number <> 0 then
wscript.echo VBTAB & "Error Connecting..." & VBTAB & Err.Number & VBTAB & Err.Description
else
on error goto 0
' Display all member names in the group
For Each objMember in objGroup.Members
'redim preserve ArrLocalMembers(UBOUND(ArrLocalMembers)+1)
'WScript.Echo vbtab & "Members....:" & objMember.Name & ".........adspath....: " & objMember.AdsPath
if instr(objMember.AdsPath,strComputer) >0 then 'must be a local computer object
wscript.echo VBTAB & strComputer & "\" & objMember.Name & " [" & RacfidLookup(objMember.Name) &"]"
else 'must be a domain object
'wscript.echo "AdsPath:" & objMember.AdsPath & ":"
'ignore first WinNT://
bit=mid(objMember.AdsPath,9)
'wscript.echo VBTAB & "Domain Lookup drill down group members...."& bit
pos=instr(bit,"/")
if pos=0 then
wscript.echo VBTAB & "Warning : Possible unresolved SID [" & objMember.AdsPath & "] needs tidying in Local Admin on :" & strComputer
else
strDomain=mid(bit,1,pos-1)
strObject=mid(bit,pos+1)
call GetDomainUsers(strDomain,strObject)
'wscript.echo VBTAB & bit & " [" & RacfidLookup(strObject) &"]"
'lookup domain users DN
'end if
end if
end if
Next
end if
on error goto 0
end function
Function GetGroupName(sComputer, sGroupSID)
' List of well know SID's is available here:
'
' Well-known security identifiers in Windows operating systems
' http://support.microsoft.com/?id=243330
on error resume next
Dim oGroupAccounts, oGroupAccount
Set oGroupAccounts = GetObject("winmgmts://" & sComputer & "/root/cimv2") _
.ExecQuery("Select Name from Win32_Group" & " WHERE Domain = '" & sComputer & "' AND SID = '" & sGroupSID & "'")
if Err.Number <> 0 then
wscript.echo VBTAB & "Error Connecting..." & VBTAB & Err.Number & VBTAB & Err.Description
else
If oGroupAccounts.Count = 0 Then
' need to use Domain = 'BUILTIN' at least for Win2k SP2
Set oGroupAccounts = GetObject( "winmgmts://" & sComputer & "/root/cimv2") _
.ExecQuery("Select Name from Win32_Group" & " WHERE Domain = 'BUILTIN' AND SID = '" & sGroupSID & "'")
End If
For Each oGroupAccount In oGroupAccounts
GetGroupName = oGroupAccount.Name
Next
end if
on error goto 0
End Function
function RacfidLookup(StrName)
dim retval
dim searchtxt
dim x
retval=""
searchtxt=UCASE(StrName)
for x = 1 to ubound(Racfids)
if searchtxt=Racfids(x) then
retval=RacfidsDesc(x)
exit for
end if
next
if retval="" then retval="RACFID not found"
RacfidLookup=retval
end function
function Notused_GetDNDomainUsers(strDomain,strObject)
if strDomain ="AVIVAGROUP" then
ldp="'LDAP://UKNCDAVIA001.avivagroup.com/dc=avivagroup,dc=com'"
else
if strDomain ="VIA" then
ldp="'LDAP://UKNWDAVIA811.via.novonet/dc=via,dc=novonet'"
else
if strDomain ="ECS" then
ldp="'LDAP://UKNCDAVIA101.ecs.com/dc=ecs,dc=com'"
else
wscript.echo "ERROR. NEw Domain:" & "PArameters...Domain & object:" & strDomain & ":" & strObject
exit function
end if
end if
end if
end function
Function GetType(intType)
' Function to determine group type from the GroupType attribute.
If (intType And &h01) <> 0 Then
GetType = "Built-in"
ElseIf (intType And &h02) <> 0 Then
GetType = "Global"
ElseIf (intType And &h04) <> 0 Then
GetType = "Local"
ElseIf (intType And &h08) <> 0 Then
GetType = "Universal"
End If
If (intType And &h80000000) <> 0 Then
GetType = GetType & "/Security"
Else
GetType = GetType & "/Distribution"
End If
End Function
Sub GetMembers(objADObject)
' Subroutine to document group membership.
' Members can be users or groups.
Dim objMember, strType
'wscript.echo "TASK GROUP..." & objADObject.name
subgroup=subgroup+1
'group_enumerated=FALSE
Err.Clear
on error resume next
For Each objMember In objADObject.Members
if Err.Number <>0 then exit for
Str_tabs=""
for loop_=1 to subgroup
Str_tabs=Str_tabs & " "
next
If UCase(Left(objMember.objectCategory, 8)) = "CN=GROUP" Then
'group_enumerated=TRUE
strType = "Group"
objects_in_group=objects_in_group+1
GetType(objGroup.groupType)
wscript.echo Str_tabs & "Contains...: " & objMember.sAMAccountName & " (" & strType & ")" & VBTAB & "[" & GetType(objGroup.groupType) & "] " & objMember.description
call GetMembers(objMember)
subgroup=subgroup-1
'wscript.Echo "Objects in group...:" & objects_in_group
Else
'strType = "User_or_computer"
objects_in_group=objects_in_group+1
if objMember.sAMAccountName="" then
wscript.Echo Str_tabs & "Contains...: " & "Errr...Possible foreign security principle....have not worked out how to get friendly name yet!....SID :" & ":" & objMember.Name
else
wscript.echo Str_tabs & "Contains...: " & objMember.sAMAccountName & " (" & RacfidLookup(objMember.sAMAccountName) & ") " & NiceDN(objMember.distinguishedName)
end if
End If
Next
on error goto 0
'Set objMember = Nothing
End Sub
function NiceDN(SStrDN)
'CN=xxxxx,OU=GRPTAX,OU=ACO,OU=User Accounts,DC=VIA,DC=NOVONET
'wscript.Echo "StrDN:" & StrDN
arr=split(SStrDN,",")
for loop_=UBOUND(arr)-2 to 1 step -1
'wscript.Echo "loop:" & loop_
NiceDN=NiceDN & "\" & mid(arr(loop_),4)
next
NiceDN= NiceDN
end function
Function IsGroup(strDN)
dim objGroup, intgroupType, retval
Set objGroup = GetObject ("LDAP://" & strDN)
objGroup.GetInfo
Err.Clear
On error resume next
descr=""
descr = objGroup.Get("description")
Err.Clear
intgroupType = objGroup.Get("groupType")
if Err.Number <> 0 then
retval="FALSE"
'wscript.echo "FALSE" & descr
'wscript.echo "DN:" & strDN
else
retval=descr
'wscript.echo "TRUE" &retval
end if
on error goto 0
IsGroup=retval
end function
Function FindComputerObject(strComputer)
dim ldp, result
strComputer=Trim(strComputer)
ldp="SELECT Name, distinguishedName, operatingSystem, operatingSystemVersion, operatingsystemservicepack FROM 'LDAP://UKNWDAVIA101.ecs.com/DC=ECS,DC=com' WHERE objectCategory='computer' and Name='" & strComputer & "'"
result = Main (ldp,"ecs.com")
if result="NotFound" then
ldp="SELECT Name, distinguishedName, operatingSystem, operatingSystemVersion, operatingsystemservicepack FROM 'LDAP://UKNWDAVIA811.VIA.NOVONET/DC=VIA,DC=NOVONET' WHERE objectCategory='computer' and Name='" & strComputer & "'"
result = Main (ldp,"via.novonet")
if result="NotFound" then
ldp="SELECT Name, distinguishedName, operatingSystem, operatingSystemVersion, operatingsystemservicepack FROM 'LDAP://UKNCDAVIA001.avivagroup.com/dc=avivagroup,dc=com' WHERE objectCategory='computer' and Name='" & strComputer & "'"
result = Main (ldp,"avivagroup.com")
if result="NotFound" then
FindComputerObject = strComputer & " Not Found"
end if
end if
end if
FindComputerObject = result
end function
function Main(SQL,StrDomain)
dim objConnection9, objCommand9, objRecordSet9, res, count, Name, bit
dim DN,pos, OS, OSver , OSsp
'wscript.echo SQL
Set objConnection9 = CreateObject("ADODB.Connection")
Set objCommand9 = CreateObject("ADODB.Command")
objConnection9.Provider = ("ADsDSOObject")
objConnection9.Open "Active Directory Provider"
objCommand9.ActiveConnection = objConnection9
objCommand9.Properties("Page Size") = 1000
objCommand9.Properties("Searchscope") = ADS_SCOPE_SUBTREE
'SQL="SELECT Name, distinguishedName, operatingSystem, operatingSystemVersion, operatingsystemservicepack FROM 'LDAP://UKNWDAVIA811.VIA.NOVONET/DC=VIA,DC=NOVONET' WHERE objectCategory='computer' and Name='" & strComputer & "'"
'SQL="SELECT Name FROM 'LDAP://UKNWDAVIA811.VIA.NOVONET/DC=VIA,DC=NOVONET' WHERE Name='UKNCSAVIA008'"
objCommand9.CommandText = SQL
'wscript.echo SQL
Set objRecordSet9 = objCommand9.Execute
on error resume next
objRecordSet9.MoveFirst
res="NotFound"
on error goto 0
Do Until objRecordSet9.EOF
'wscript.echo "Hereeeee"
Name= objRecordSet9.Fields("Name").Value
bit=mid(Name,1,2)
if UCASE(bit)="VW" or UCASE(bit)="LT" or UCASE(bit)="WS" or UCASE(bit)="TB" or UCASE(bit)="DR" then
'ignore
else
count=count +1
DN = objRecordSet9.Fields("distinguishedName").Value
pos = instr(DN,",")
DN = mid(DN,pos+1)
OS = objRecordSet9.Fields("operatingSystem").Value
OSver = objRecordSet9.Fields("operatingSystemVersion").Value
OSsp = objRecordSet9.Fields("operatingsystemservicepack").Value
res= Name & "." & StrDomain & VBTAB & NiceDN(objRecordSet9.Fields("distinguishedName").Value) & VBTAB & OS & VBTAB & OSver & VBTAB & OSsp
end if
objRecordSet9.MoveNext
'if count >1000 then exit do
Loop
'wscript.echo "Total : " & count
Main=res
end function
function IsInGroup(userDN,strGroupDN)
dim objGroup
'only goes first layer down for nexted groups
'this is very slow
set objGroup = GetObject("LDAP://UKNWDAVIA811.via.novonet/" & strGroupDN)
ingroup="FALSE"
for each objMember in objGroup.Members
'wscript.Echo "Is USER...:" & userDN
'wscript.echo "in group :" & strGroupDN
'wscript.echo " DN:" & objMember.distinguishedName
'wscript.echo "UserDN:" & userDN
if UCASE(objMember.distinguishedName) = userDN then
ingroup="TRUE"
exit for
end if
next
IsInGroup=ingroup
end function
Function NOTUSEDIsInGroup(userDN,groupName)
dim Username
Username=ShortDN(userDN)
If IsEmpty(groupListD) then
Set groupListD = CreateObject("Scripting.Dictionary")
groupListD.CompareMode = TextCompare
'ADSPath = EnvString("userdomain") & "/" & EnvString("username")
Set userPath = GetObject("WinNT://" & "UKNWDAVIA811.via.novonet/" & Username & ",user")
For Each listGroup in userPath.Groups
groupListD.Add listGroup.Name, "-"
Next
End if
IsInGroup = CBool(groupListD.Exists(groupName))
End Function
function GetDN(StrName) 'StrName can be a group or user
'On Error Resume Next
dim objConnection2,objCommand2,objUser2,objRecordSet2,strDN2
strDN2=""
Const ADS_SCOPE_SUBTREE = 2
Set objConnection2 = CreateObject("ADODB.Connection")
Set objCommand2 = CreateObject("ADODB.Command")
objConnection2.Provider = "ADsDSOObject"
objConnection2.Open "Active Directory Provider"
Set objCommand2.ActiveConnection = objConnection2
objCommand2.Properties("Page Size") = 1000
objCommand2.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand2.CommandText = _
"SELECT distinguishedName FROM 'LDAP://dc=VIA,dc=NOVONET' WHERE objectCategory='user' " & _"AND sAMAccountName = '" & StrName & "'"
strQuery="Select Name,distinguishedName,objectclass from 'LDAP://UKNWDAVIA811.via.novonet/dc=VIA,dc=NOVONET' where objectClass='group' and ( Name ='" & StrName & "') OR objectCategory='user' and ( sAMAccountNAme ='" & StrName & "') "
'"LDAP://UKNWDAVIA811.via.novonet/" & trbhere
objCommand2.CommandText = strQuery
Set objRecordSet2 = objCommand2.Execute
If objRecordSet2.EOF Then
'Wscript.Echo "WARNING : No objects found for " & objCommand2.CommandText
else
objRecordSet2.MoveFirst
Do Until objRecordSet2.EOF
strDN2 = objRecordSet2.Fields("distinguishedName").Value
objRecordSet2.MoveNext
Loop
end if
'Set objUser = GetObject("LDAP://" & strDN)
'Wscript.Echo objUser.Name
GetDN=strDN2
end function
function ListUserGroups(strUserDN)
DN=GetDN(strUserDN)
if DN="" then
ListUserGroups=""
wscript.Echo VBTAB & "ERROR : no such user"
call Clear_Array(TempUserGroup)
exit function
end if
Set objUser = GetObject ("LDAP://UKNWDAVIA811.via.novonet/" & DN)
intPrimaryGroupID = objUser.Get("primaryGroupID")
arrMemberOf = objUser.GetEx("memberOf")
If Err.Number = E_ADS_PROPERTY_NOT_FOUND Then
WScript.Echo VBTAB & strUserDN & "The memberOf attribute is not set...ie no groups"
Else
For each Group in arrMemberOf
call AddToArrays(UCASE(Group))
Next
End If
'below gets the name of primary group from token
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'objCommand.CommandText = "<LDAP://dc=VIA,dc=NOVONET>;(objectCategory=Group);" & "distinguishedName,primaryGroupToken;subtree"
objCommand.CommandText = "<LDAP://UKNWDAVIA811.via.novonet/dc=VIA,dc=NOVONET>;(objectCategory=Group);" & "distinguishedName,primaryGroupToken;subtree"
Set objRecordSet = objCommand.Execute
bit=""
on error resume next
While Not objRecordset.EOF
If objRecordset.Fields("primaryGroupToken") = intPrimaryGroupID Then
'WScript.Echo VBTAB & "Primary group:"
bit=objRecordset.Fields("distinguishedName")
if bit <>"" then call AddToArrays(UCASE(bit))
End If
objRecordset.MoveNext
Wend
objConnection.Close
on error goto 0
end function
function Clear_Array(arr)
redim arr(0)
end function
function notusedIsInArray2(searchtxt) 'searchtxt is a DN
wscript.echo "searchtxt:" & searchtxt & ":"
dim l
IsInArray2=0
for l = 1 to UBOUND(groups1)
wscript.echo "groups1(l):" & groups1(l) & ":"
if searchtxt=groups1(l) then
IsInArray2=l
exit function
end if
next
end function
function NOTUSEDIsInArray(searchtxt) 'searchtxt is a DN
dim l
dim res
res=-1
'wscript.echo "isinarr searchtxt :" &searchtxt
for l = 1 to UBOUND(groups1)
'wscript.echo "isinarr groups1 :" & l & VBTAB & groups1(l)
if instr(searchtxt, groups1(l))=4 then
res=l
exit for
end if
next
if res=-1 then
'wscript.echo "isinarr Not FOUND"
else
'wscript.echo "isinarr FOUND at : " & res
end if
IsInArray=res
end function
function AddToArrays(StrTxt)
dim l
dim res,bit
tempcount=tempcount+1
'wscript.echo tempcount & VBTAB & "StrTxt :" & StrTxt &":"
for l = 1 to UBOUND(groups1)
'wscript.echo "Groups1 :" & l & VBTAB & ":" & groups1(l) &":"
if groups1(l)=StrTxt then
redim preserve TempUserGroupAdd(UBOUND(TempUserGroupAdd)+1)
TempUserGroupAdd(ubound(TempUserGroupAdd))=groups2(l)
redim preserve TempUserGroup(UBOUND(TempUserGroup)+1)
TempUserGroup(ubound(TempUserGroup))=UCASE(StrTxt)
'wscript.Echo "FFFFOUND" & VBTAB & UBOUND(TempUserGroup) &" " & groups1(l)
'exit for
end if
next
'if res=-1 then
'wscript.echo "isinarr Not FOUND"
'else
'wscript.echo "isinarr FOUND at : " & res
'end if
end function
function Helpp
wscript.echo "ERROR : Parameter 1 missing"
wscript.quit
end function
'SIMULATED="FALSE"
'usr="CN=TTBURROUT,OU=DIRECTORY SERVICES,OU=HP ENTERPRISE SERVICES,OU=NUCS,OU=USER ACCOUNTS,DC=VIA,DC=NOVONET"
'ggroup="CN=SBC_ROL_LIVE_LIFE_ADMINRE06,OU=USER ROLES,OU=CITRIX GROUPS,OU=APP DELEGATION,OU=SECURITY,OU=GROUPS,DC=VIA,DC=NOVONET"
'call RemoveUserFromgroup(ggroup,usr)
'usr="CN=TTBURROUT,OU=DIRECTORY SERVICES,OU=HP ENTERPRISE SERVICES,OU=NUCS,OU=USER ACCOUNTS,DC=VIA,DC=NOVONET"
'ggroup="CN=SBC_ROL_LIVE_LIFE_ADMINRE06,OU=USER ROLES,OU=CITRIX GROUPS,OU=APP DELEGATION,OU=SECURITY,OU=GROUPS,DC=VIA,DC=NOVONET"
'call RemoveUserFromgroup(ggroup,usr)
'SIMULATED="FALSE"
'usr="CN=TTBURROUT,OU=DIRECTORY SERVICES,OU=HP ENTERPRISE SERVICES,OU=NUCS,OU=USER ACCOUNTS,DC=VIA,DC=NOVONET"
'ggroup="CN=SBC_ROL_LIVE_LIFE_ADMINRE06,OU=USER ROLES,OU=CITRIX GROUPS,OU=APP DELEGATION,OU=SECURITY,OU=GROUPS,DC=VIA,DC=NOVONET"
'call AddUserToGroup(ggroup,usr)
'usr="CN=TTBURROUT,OU=DIRECTORY SERVICES,OU=HP ENTERPRISE SERVICES,OU=NUCS,OU=USER ACCOUNTS,DC=VIA,DC=NOVONET"
'ggroup="CN=SBC_ROL_LIVE_LIFE_ADMINRE06,OU=USER ROLES,OU=CITRIX GROUPS,OU=APP DELEGATION,OU=SECURITY,OU=GROUPS,DC=VIA,DC=NOVONET"
'call AddUserToGroup(ggroup,usr)
'wscript.quit
The below script is not working from windows 2003 to windows 2008.
- VBScript used on windows ENV to migrate the users.
- The script was run on a Windows 2003 machine.
- Now it has compatible issues in running on Windows 2008 server.
- The script was last run some 4-5 months back on 2008 server and it failed, now we do not have any
windows 2003 servers.
- The requirement out here is to come up with a script or, windows PowerShell scripting or, any other mean to migrate the users.