Posts Tagged ‘Scripting’

Scripting – Sample Users/Group creation in AD

Posted in English Articles  by kissdeath on May 18th, 2009
Set oRoot = GetObject(“LDAP://rootDSE“)
Set oDomain = GetObject(“LDAP://” & oRoot.Get(“defaultNamingContext”))
Set oOU=oDomain.Create(“organizationalUnit”, “ou=My Corp Users”)
oOU.SetInfo
Set oUser = oOU.Create(“User”, “cn=Director One”)
oUser.Put “sAMAccountName”, “director1″
oUser.SetInfo
oUser.givenName=”Director One”
oUser.displayName=”Director One”
oUser.title=”Managing Director”
oUser.department=”Director Dept”
oUser.mail=”director1@mycompany.com.vn
oUser.employeeID=789
SetCommonProps(oUser)
Set oUser = oOU.Create(“User”, “cn=Manager One”)
oUser.Put “sAMAccountName”, “manager1″
oUser.SetInfo
oUser.givenName=”Manager One”
oUser.displayName=”Manager One”
oUser.title=”Sales Manager”
oUser.department=”Sales & Marketing Dept”
oUser.mail=”manager1@mycompany.com.vn
oUser.employeeID=678
oUser.manager=”CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
SetCommonProps(oUser)
Set oUser = oOU.Create(“User”, “cn=Staff One”)
oUser.Put “sAMAccountName”, “staff1″
oUser.SetInfo
oUser.givenName=”Staff One”
oUser.displayName=”Staff One”
oUser.title=”Sales Executive”
oUser.department=”Sales & Marketing Dept”
oUser.mail=”staff1@mycompany.com.vn
oUser.employeeID=123
oUser.manager=”CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
SetCommonProps(oUser)
Set oUser = oOU.Create(“User”, “cn=Staff Two”)
oUser.Put “sAMAccountName”, “staff2″
oUser.SetInfo
oUser.givenName=”Staff Two”
oUser.displayName=”Staff Two”
oUser.title=”Cashier”
oUser.department=”Sales & Marketing Dept”
oUser.mail=”staff2@mycompany.com.vn
oUser.employeeID=234
oUser.manager=”CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
SetCommonProps(oUser)
Set oUser = GetObject(“LDAP://CN=Administrator,CN=Users,DC=mycompany,DC=com,DC=vn“)
oUser.givenName=”Administrator”
oUser.displayName=”Administrator”
oUser.title=”System Admin”
oUser.department=”Director Dept”
oUser.mail=”administrator@mycompany.com.vn
oUser.employeeID=012
oUser.manager=”CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
oUser.SetInfo
SetCommonProps(oUser)
Set oGroup = oOU.Create(“Group”, “cn=Directors”) ‘Global group creation
oGroup.Put “sAMAccountName”, “Directors”
oGroup.SetInfo
oGroup.member=”CN=Director One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
oGroup.SetInfo
Set oGroup = oOU.Create(“Group”, “cn=Chief Accountants”)
oGroup.Put “sAMAccountName”, “ChiefAccountants”
oGroup.SetInfo
oGroup.member=”CN=Manager One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
oGroup.SetInfo
Set oGroup = oOU.Create(“Group”, “cn=Accountants”) ‘Global group creation
oGroup.Put “sAMAccountName”, “Accountants”
oGroup.SetInfo
oGroup.member=”CN=Staff One,OU=My Corp Users,DC=mycompany,DC=com,DC=vn”
oGroup.SetInfo
Wscript.Echo “Users/Groups Creation Successul!”
sub SetCommonProps(oUser)
oUser.SetPassword “P@ssw0rd
oUser.AccountDisabled = False
oUser.company=”My Company”
oUser.streetAddress=”123 XYZ Street”
oUser.l=”Hanoi”
oUser.c=”VN”
oUser.telephoneNumber=”+84-4-123-45678″
oUser.mobile=”+84-9-1234-5678″
oUser.userAccountControl=66080 ’0×10220=PASSWD_NOTREQD|NORMAL_ACCOUNT|DONT_EXPIRE_PASSWD)
oUser.SetInfo
end sub

Tags:

ISA Server logging

Posted in English Articles, Security, Templates  by kissdeath on May 18th, 2009

In order to query the log, in addtion to the builtin query viewer of ISA, you can install SQL client tools, then use SQL Analyzer to connect to ISA-SERVER\MSFW (replace ISA-SERVER with your actual server name) and query the log. See the example here.

The builtin query viewer of ISA can show only the first 10,000 log records.

In addition, you can use the script to show the log entries. A sample script can be downloaded here. It can query the last 30 days of log. Just download it, rename it to a *.vbs file, and run it on your ISA Server. Make sure to change the first 2 input data (LogDate and ClientUserName) in the script file to match your actual data before runing. And, don’t forget that the script syntax is cscript LogQuery.vbs [LogData.txt]

Below is a sample result of a script query.
ISA log query using script

To further customize the script, you can study the ISA constants in an SDK include file named comenum.h. Other ISA development topics can be found here.

Tags:

Some Usefull .vbs Script

Posted in English Articles, Useful Links  by kissdeath on February 17th, 2009

Script That Displays Group Membership and Active Directory Location

The following code can be run to display the group membership of an Active Directory group and also let you know each member’s LDAP Distinguished Name.  The output will name the text file the group name and will include all the members and their location in Active Directory.  Just copy this into a txt file and rename to .vbs  Enjoy!

Set objGroup = GetObject(“LDAP://cn=GroupName,ou=OUName,DC=DomainName,DC=local“)
Set objFileSystem = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFileSystem.OpenTextFile(objGroup.Get(“name”) & ” – Members.txt“, 2, True, 0)
For Each objMember in objGroup.Members
objFile.WriteLine objMember.Get(“sAMAccountName”) & VbTab & _
objMember.Get(“cn”) & VbTab & _
objMember.Parent
Next
Set objFile = Nothing
Set objFileSystem = Nothing
Set objGroup = Nothing

Export Email Addresses from a Distribution Group

One thing that really bugs me is there is no easy way to grab some email addresses from a distribution group.  Usually I end up expanded the group to list all the users and then I have to go to the Outlook properties of each user to view the email address.  Heck, I can’t even copy the email address from there…instead I have to write it down.  This can be a pain for companies that have long complex email addresses.

I’ve finally figured out a way to export this info into a text file…no one said I was quick.  :)   To do this you just need to use either CSVDE or LDIFDE.  I use mail as the attribute I pull from these commands but you could really use any AD attribute that you want to pull.

csvde -f c:\temp\report.txt -r “memberOf=cn=group name,ou=ou name,dc=domain,dc=name” -l mail

ldifde -f c:\temp\report.txt -r “memberOf=cn=group name,ou=ou name,dc=domain,dc=name” -l mail

This may not be the cleanest way to pull this data but at least now I can copy and paste the email addresses.

Script to Determine Members of a Group

DSGET GROUP CN=West_Coast_Sales,OU=Sales,OU=GROUPS,DC=adminprep,DC=com -MEMBERS –EXPAND

“CN=bmiller,OU=Sales,DC=adminprep,DC=com ”
“CN=jsmith,OU=Sales,DC=adminprep,DC=com ”
“CN=dregan,OU=Sales,DC=adminprep,DC=com ”
“CN=lramero,OU=Sales,DC=adminprep,DC=com ”
“CN=cpeters,OU=Sales,DC=adminprep,DC=com ”
“CN=jhorton,OU=Sales,DC=adminprep,DC=com “

How to Display the Groups a User is a Member of

I’ve been trying to work more and more with scripts and today I’m sharing a simple but useful one. How to display the groups a user account is a member of. To display a user’s groups via the command prompt you need to use the dsget command with the -memberof and -expand switches. The -expand command will list all of the groups that you belong to that are nested in other groups.
Below is an example of how this would look:

dsget user “CN=Brian W. McCann,OU=Users,OU=Sales,DC=Adminprep,DC=com” -memberof -expand

The output would look similar to this:

“CN=GG Sales,OU=Groups,OU=Sales,DC=Adminprep,DC=com”
“CN=Domain Admins,CN=Users,DC=Adminprep,DC=com”
“CN=Domain Users,CN=Users,DC=Adminprep,DC=com”
“CN=GG Inside Sales,OU=Groups,OU=Sales,DC=Adminprep,DC=com”
“CN=GG Outside Sales,OU=Groups,OU=Sales,DC=Adminprep,DC=com”
“CN=Administrators,CN=Builtin,DC=Adminprep,DC=com”
“CN=Users,CN=Builtin,DC=Adminprep,DC=com”

From Source.

Tags: