Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Create an AD Group with Alternate Credentials

Reply
 
Old 07-31-2009   #1 (permalink)
OldDog


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46