kev_147 Posted June 21, 2006 Posted June 21, 2006 Guys,Can anyone help me with a script. This is the scenario:I am logged into a PC as local administrator and need to run a script that will go out to the domain and get a domain group called "ICT-Desktop Support" and add this group to the local administrators group.I think I have to use some of the following code to authenticate on the domain:Const ADS_SCOPE_SUBTREE = 2Set objConnection = CreateObject("ADODB.Connection")Set objCommand = CreateObject("ADODB.Command")objConnection.Provider = "ADsDSOObject"objConnection.Properties("User ID") = "fabrikam\kenmyer" ;change accordinglyobjConnection.Properties("Password") = "A2sXrco1Fq1#om!" ;change accordinglyobjConnection.Properties("Encrypt Password") = TRUEobjConnection.Properties("ADSI Flag") = 3objConnection.Open "Active Directory Provider"Set objCommand.ActiveConnection = objConnectionobjCommand.Properties("Page Size") = 1000objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE And some of the following code to add the group: strComputer = "." strLocalGroup = "Administrators" strDomainGroup = "ICT-Desktop Support" 'Look up local group. Set objLocalGroup = GetObject("WinNT://" & strComputer & "/" & strLocalGroup & ",group") ' Look up Domain group to be checked against local group. Set objDomainGroup = GetObject( "WinNT://" & strDomain & "/" & strDomainGroup & ",group") 'Check if domain group already a member. If not objLocalGroup.IsMember(objDomainGroup.AdsPath) Then 'Add domain group to local group. objLocalGroup.Add(objDomainGroup.AdsPath) Else End IfBut I am not sure howto put them together. Can anyone help me please???
allen2 Posted June 21, 2006 Posted June 21, 2006 Why not simply do a batch:net localgroup administrators "fabrikam\ICT-Desktop Support" /add
kev_147 Posted June 21, 2006 Author Posted June 21, 2006 If that works logged on as just a local administrator and not being authenticated into the domain at all then great.Could someone assist in getting that command to work in vbscript please. I have this so far, but it isn't working. The reason I want it in vbscript is because this is only a small part of something that is embedded in a hta file using vbscript.Set WshShell = WScript.CreateObject("WScript.Shell")net1 = "net localgroup administrators "net2 = "cos.sunderland.local\ICT-Desktop Support"net3 = " /add"wscript.echo net1wscript.echo net2wscript.echo net3wscript.echo net1 & net2 & net3WshShell.Run(net1 & net2 & net3)Thanks in advance guys
gunsmokingman Posted June 22, 2006 Posted June 22, 2006 Try this change to meet your needsDim Act : Set Act = CreateObject("Wscript.Shell") Act.Run("%Comspec% /c net localgroup administrators ""fabrikam\ICT-Desktop Support"" /add"), 0, True
kev_147 Posted June 22, 2006 Author Posted June 22, 2006 I done it like this in the end.Thanks for pointing me in the right direction gsh.'---------------------------------------------------------------------Dim Act, strDomain, strDomainGroupOn Error Resume NextSet Act = CreateObject("Wscript.Shell")strDomain = Chr(34) & "COS.Sunderland.Local"strDomainGroup = "\ICT-Desktop Support" & Chr(34)Act.Run("%Comspec% /c net localgroup administrators " & strDomain & strDomainGroup & " /add"), 0, True'---------------------------------------------------------------------
kev_147 Posted June 23, 2006 Author Posted June 23, 2006 Does anyone know why this command is only pulling through the SID of the group and not the actual name?I am running this script at the same time as joining the PC to the domain and before a reboot.Don't worry guys, I think I have worked it out. It is because I am joining the PC to the root domain.Am just about to test joining the PC to the normal domain name instead to see if that works.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now