3
Aug/10
0

VB Script: Copy Active Directory Group Members

VB Script that copies all members of Group A to Group B. Requires 2 Arguments (Source Group Name, Destination Group Name)

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
47
48
49
50
51
Set objSystemInfo = CreateObject("ADSystemInfo") 
strDomain = objSystemInfo.DomainShortName
 
strSGroupDN = GetObjectDN(WScript.Arguments(0), strDomain)
strDGroupDN = GetObjectDN(WScript.Arguments(1), strDomain)
 
WScript.Echo ""
WScript.Echo "     Source Group: " & strSGroupDN 
WScript.Echo "Destination Group: " & strDGroupDN 
WScript.Echo ""
 
set dicSeenGroupMember = CreateObject("Scripting.Dictionary")
set objDGroup = GetObject("LDAP://" & strDGroupDN)
 
CopyMembers "LDAP://" & strSGroupDN, dicSeenGroupMember
 
Function CopyMembers (strGroupADsPath, dicSeenGroupMember)
	set objGroup = GetObject(strGroupADsPath)
	WScript.Echo "Adding Users to " & WScript.Arguments(1)
	for each objMember In objGroup.Members
		On Error Resume Next
		If (objDGroup.Add("LDAP://" & objMember.distinguishedName)) Then
			WScript.Echo "  " & objMember.displayName & " (Already Member)"
		Else 
			WScript.Echo "  " & objMember.displayName
		End If
	next
End Function
 
Function GetObjectDN(strObject, strDomain)
	Const ADS_NAME_INITTYPE_GC = 3
	Const ADS_NAME_TYPE_1779 = 1
	Const ADS_NAME_TYPE_NT4 = 3
 
	Dim objNameTranslate
	Dim strObjectDN
 
	On Error Resume Next : Err.Clear
	Set objNameTranslate = CreateObject("NameTranslate")
 
	objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""
	objNameTranslate.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strObject
	strObjectDN = objNameTranslate.Get(ADS_NAME_TYPE_1779)
	If Err.Number <> 0 Then
		strObjectDN = ""
	End If
 
	Set objNameTranslate = Nothing
	On Error Goto 0
	GetObjectDN = strObjectDN
End Function
Print This Post
(2 votes, average: 5.00 out of 5)
Loading ... Loading ...
76 views
20
May/10
0

Change Outlook 2003 Free Busy Update Information

Here’s a small batch that changes Outlook Free Busy Information in your local Registry.

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
47
48
49
50
51
52
53
54
55
56
57
58
59
@ECHO OFF
 
SET FBPublishRange=%1
SET FBUpdateSecs=%2
 
IF NOT DEFINED FBPublishRange (
  SET FBPublishRange=6
  )
IF %FBPublishRange% LSS 1 (
  GOTO :HELP)
IF %FBPublishRange% GTR 12 (
  GOTO :HELP)
 
IF NOT DEFINED FBUpdateSecs (
  SET FBUpdateSecs=1800
  )
IF %FBUpdateSecs% LSS 1800 (
  GOTO :HELP)
IF %FBUpdateSecs% GTR 7200 (
  GOTO :HELP)
 
ECHO Updating Outlook Free Busy Options  
ECHO  Updating FBPublishRange using value %FBPublishRange%
reg add HKCU\Software\Microsoft\Office\11.0\Outlook\Preferences /t REG_DWORD /v FBPublishRange /d %FBPublishRange% /f>NUL
ECHO  Updating FBUpdateSecs using value %FBUpdateSecs%
reg add HKCU\Software\Microsoft\Office\11.0\Outlook\Preferences /t REG_DWORD /v FBUpdateSecs /d %FBUpdateSecs% /f>NUL
IF %ERRORLEVEL% EQU 0 (
	ECHO Update Completed Successfully
  GOTO :EOF
	) ELSE (
	ECHO There was an error updating Outlook Free Busy Options. Return Value: %ERRORLEVEL%
	GOTO :EOF
	)
:HELP
ECHO.
ECHO Invalid Arguments Found
ECHO ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ECHO.
ECHO Allows 2 optional arguments: [FBPublishRange] and [FBUpdateSecs]
ECHO.
ECHO Argument 1 specifies the number of months to publish Free/Busy information
ECHO   Valid values for argument 1 (FBPublishRange): 1 to 12
ECHO.
ECHO Argument 2 specifies the update interval to publish Free/Busy information
ECHO   Valid values for argument 2 (FBUpdateSecs): 1800 to 7200
ECHO.
ECHO Examples:
ECHO.
ECHO "UpdateOutlookFreeBusy.cmd" Uses default values 
ECHO   -FBPublishRange = 6, FBUpdateSecs = 1800
ECHO.
ECHO "UpdateOutlookFreeBusy.cmd 9"
ECHO   -FBPublishRange = 9, FBUpdateSecs = 1800
ECHO.
ECHO "UpdateOutlookFreeBusy.cmd 9 2400"
ECHO   -FBPublishRange = 9, FBUpdateSecs = 2400
GOTO :EOF
 
:EOF
Print This Post
(No Ratings Yet)
Loading ... Loading ...
197 views
18
Feb/10
0

Add Domain Users / Groups to local Groups remotely

Script that adds a Domain User to a local Group remotely.

Change the “DomainName” variable to suit your requirements.

Requires 3 Arguments:
[Machine Name] [Local Group to modify] [Domain User/Group to add]

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
If (WScript.Arguments.Count < 3) Then
        WScript.Echo "3 Arguments required: [Machine Name] [Local Group to modify] [Domain User/Group to add]"
        WScript.Quit 1
End If
 
Dim DomainName
Set net = WScript.CreateObject("WScript.Network")
 
DomainName = "yourdomain.com"
 
WScript.Echo ""
WScript.Echo WScript.Arguments(0)
WScript.Echo "==================="
 
set group = GetObject("WinNT://"& WScript.Arguments(0) &"/"& WScript.Arguments(1) &"")
 
on error resume next
 
WScript.Echo "Before:"
For Each objUser In group.Members
  WScript.Echo objUser.Name
next
group.Add "WinNT://"& DomainName &"/"& WScript.Arguments(2) &""
CheckError
 
sub CheckError
        if not err.number=0 then
        set ole = CreateObject("ole.err")
                WScript.Echo ole.oleError(err.Number)
                err.clear
        else
                WScript.Echo ""
                WScript.Echo "After:"
                For Each objUser In group.Members
                  WScript.Echo objUser.Name
                next
        end if
end sub
Print This Post
(1 votes, average: 4.00 out of 5)
Loading ... Loading ...
509 views
18
Feb/10
0

Get Service Pack Levels of Servers via Active Directory

Script that queries Active Directory to retrieve Service Pack Levels (In this example only from Windows Server 2003 Machines)
Modify the strContainer variable to your requirements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
On Error Resume Next
 
Const ADS_SCOPE_SUBTREE = 2
strContainer = "DC=yourdomain,DC=com"
 
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Page Size") = 1000
objCommand.CommandText = _
  "SELECT CN, operatingSystem, operatingSystemVersion, operatingSystemServicePack FROM 'LDAP://" & strContainer & "' " _
   & "WHERE objectCategory='computer' AND operatingSystem = 'Windows Server 2003' "
Set objRecordSet = objCommand.Execute
objRecordSet.Sort = "CN"
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
  Wscript.Echo objRecordSet.Fields("CN").Value & "," & objRecordSet.Fields("operatingSystem").Value & "," & objRecordSet.Fields("operatingSystemVersion").Value & "," 
  & objRecordSet.Fields("operatingSystemServicePack").Value
  objRecordSet.MoveNext
Loop
Print This Post
(1 votes, average: 5.00 out of 5)
Loading ... Loading ...
240 views
18
Feb/10
0

Set the local User Password remotely via script

3 simple Lines that update a local account using WinNT on a computer.
Requires 3 Arguments:
[Machine Name] [Local User] [New Password]

1
2
3
4
5
6
7
If (WScript.Arguments.Count &lt; 3) Then
   WScript.Echo "3 Arguments required: [Machine Name] [Local User] [New Password]"
   WScript.Quit 1
End If
Set objUser = GetObject("WinNT://" &amp; WScript.Arguments(0) &amp; "/" &amp; WScript.Arguments(1) &amp; ", user")
objUser.SetPassword WScript.Arguments(2)
objUser.SetInfo
Print This Post
(2 votes, average: 5.00 out of 5)
Loading ... Loading ...
231 views