![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Create an AD Group with Alternate Credentials Hi, I am trying to create a script that will determine if a group exist and if not, create it. I need to do this using alternate credentials, so I thought ADO might be the way to go. I have seen Programs to document and administer groups, But, I did not see one to create groups. TIA, OldDog Function to see if group exist: AD_Obj = "Group name" GetADSPathOU(AD_Obj) Function GetADSPathOU(AD_Obj) ' On Error Resume Next Const ADS_SCOPE_SUBTREE = 2 DNC = GetObject("LDAP://RootDSE").Get("defaultNamingContext") Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Properties("User ID") = "Administrator" objConnection.Properties("Password") = "+77m5trgJo!" objConnection.Properties("Encrypt Password") = TRUE objConnection.Properties("ADSI Flag") = 1 objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE If Trim(AD_Obj) = "" Then ADobj = "Administrator" : AD_Obj.Value = "Administrator" Else ADobj=Trim(AD_Obj) End If objCommand.CommandText = "SELECT Adspath FROM 'LDAP://" & DNC & "'" & _ " WHERE name='" & ADobj & "'" & " OR sAMAccountName='" & ADobj & "'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst If Err <> 0 Then If Err.Number = 3021 Then TxtADSPath.Value = Trim(AD_Obj.Value) & " Not Found!!!" Else TxtADSPath.Value = Err.Number & " " & Err.Description End If txtou.Value = "" Err.Clear Exit Function End If arrAD = Split(objRecordSet.Fields("AdsPath").Value, ",") For i = 0 to Ubound(arrAD) If InStr(arrAD(i), "OU=") Or InStr(arrAD(i), "LDAP://OU=") Then iLength = Len(arrAD(i)) leading = iif(InStr(arrAD(i),"LDAP://OU="),10,3) OULength = iLength - leading OU = Right(arrAD(i), OULength) Exit For End If Next TxtADSPath = objRecordSet.Fields("Adspath").Value objRecordSet.MoveNext MsgBox TxtADSPath & VbCrLf & "Done" End Function Function iif(cond,t,f) If cond Then iif = t Else iif = f End If End Function |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Creating or copying a file with alternate credentials | VB Script | |||
| Executing LNK files with alternate credentials | PowerShell | |||
| executing ps1 from a web browser, alternate credentials | PowerShell | |||
| running script with alternate credentials | PowerShell | |||
| PoSh Remote/Alternate Credentials | PowerShell | |||