First of all I have to say this is not the most flexible way of doing it, especially if you have a few different domains to check for, but it should give you a lead on 'how-to'.
- Option Explicit
- On Error Resume Next
- Dim oWS : Set oWS = WScript.CreateObject("WScript.Shell")
- Dim oFS : Set oFS = CreateObject("Scripting.FileSystemObject")
- Dim oWN : Set oWN = CreateObject("Wscript.Network")
- Const ADS_SCOPE_SUBTREE = 2
- Set objConnection = CreateObject("ADODB.Connection")
- Set objCommand = CreateObject("ADODB.Command")
- objConnection.Provider = "ADsDSOObject"
- objConnection.Open "Active Directory Provider"
- Set objCommand.ActiveConnection = objConnection
- objCommand.Properties("Page Size") = 1000
- objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
- objCommand.CommandText = "Select ADsPath, Name From 'LDAP://dc=my,dc=domain,dc=com' Where objectCategory = 'Group' AND Name='AD-Migration'"
- Set objRecordSet = objCommand.Execute
- objRecordSet.MoveFirst
- Set objGroup = GetObject(objRecordSet.Fields("ADsPath").Value)
- Dim UserInGroup
- UserInGroup=False
- For Each strUser in objGroup.Member
- set objUser=GetObject("LDAP://"+struser)
-
- if (LCase(objUser.samaccountname)=LCase(oWN.UserName)) then
- UserInGroup=True
- end if
- Next
- if(UserInGroup=True)then
- oWS.Run("wscript.exe .\AD_UserProfileMigration\migrate_station.vbs")
- else
- Wscript.Quit(0)
- end if
I'll just assume you know your programming bits and go on from top to bottom:
Create default objects for Filesystem, Scriptshell and Network. Though I do not need all of them in this one, the main logonscript has all of those in use. So I just included them here too.
Next thing we do is setting up a query for LDAP to our domain where we look for the specific group 'AD-Migration'. All members of that group have to be migrated to the new Domain.
The beauty of this is that you can stuff a new member in there on the On-Site-DC and the change is immideatly done.. no relog.. no gpupdate... just restart the script.
Next step is to interate through all members and see if their current logonname matches the logonname in the group. Next Gotcha... MS calls this 'SamAccountName' in the AD-Schema. And... great praise to whoever dreamed that up... the description in the schema is... *drumroll* 'SamAccountName' DUH...
So... we set a boolean to 'true' if we found the name and start the script(s) accordingly... no magic there...
I hope this did help you a bit on your way... I have some recommended reading though:
- The windows script Help (v5.6 at the moment). Won't link it here, because it is likely to change in URL. Just search on MS.com.
- Windows Server Support Tools. These bring the 'Active Directory Schema' Add-In for the Managementconsole
Questions welcome :)
See you soon,
Dirk
P.S.:
Yes, actual workingcode directly from our logonscript. I works, honestly!
No comments:
Post a Comment