Difference between revisions of "Windows Server 2008"

From Blue-IT.org Wiki

(AD User export / import)
 
(2 intermediate revisions by the same user not shown)
Line 28: Line 28:
 
Many thanks to T. Hopf.
 
Many thanks to T. Hopf.
  
WARNING: The script will  
+
'''WARNING: The script will alter you AD without any prompts! Be shure to know what you are doing!'''
  
 
Therefore three files are necessary laying in the same directory:
 
Therefore three files are necessary laying in the same directory:
  
Export a list of users from the Active Directory and save it as: '''user.txt'''.
+
=== 1. Export a list of users from the Active Directory ===
 +
and save it as: '''user.txt'''
  
Save this as '''ChangePWonLogon.vbs'''
+
=== 2. Save this as '''ChangePWonLogon.vbs''' ===
 
  @echo off
 
  @echo off
 
  net user %1 /logonpasswordchg:yes
 
  net user %1 /logonpasswordchg:yes
  
Save this as '''import_users.vbs''':
+
=== 3. Save this as '''import_users.vbs''' ===
 
  Option Explicit
 
  Option Explicit
 
  '****************************************************
 
  '****************************************************
Line 130: Line 131:
 
  WScript.Echo(Counter & " Benutzer wurden angelegt !")
 
  WScript.Echo(Counter & " Benutzer wurden angelegt !")
 
  WScript.Quit(0)
 
  WScript.Quit(0)
 +
 +
[[Category:Windows Server]]

Latest revision as of 20:18, 8 January 2012

Time Server

Setting the primary domain controller to use an internet timeserver:

echo Setting timeserver
REM w32tm /config /manualpeerlist:ptbtime1.ptb.de /syncfromflags:manual /reliable:yes /update

w32tm /config /manualpeerlist:"ptbtime1.ptb.de ptbtime2.ptb.de ptbtime3.ptb.de de.pool.ntb.org" /syncfromflags:manual /reliable:yes
w32tm /config /update

net stop w32time
REM w32tm /unregister
REM w32tm /register
net start w32time

echo Send time to clients
w32tm /resync

w32tm /monitor

net time

If you have an environment with more than one machine, you can set a local server (e.g. the primary domain controller) as ntp server:

w32tm /config /manualpeerlist:"192.168.x.x ptbtime1.ptb.de ptbtime2.ptb.de ptbtime3.ptb.de de.pool.ntb.org" /syncfromflags:manual /reliable:yes

AD User export / import

Many thanks to T. Hopf.

WARNING: The script will alter you AD without any prompts! Be shure to know what you are doing!

Therefore three files are necessary laying in the same directory:

1. Export a list of users from the Active Directory

and save it as: user.txt

2. Save this as ChangePWonLogon.vbs

@echo off
net user %1 /logonpasswordchg:yes

3. Save this as import_users.vbs

Option Explicit
'****************************************************
'Variablen Deklaration
'****************************************************
Dim fso, f, Zeile, Feld, Counter
Const DateiName="ad_exportierte_benutzerliste.txt" ' File mit den Benutzern
Const Passwort = "geheimespasswort"
Const Domain = "domänenname"
Const TopLeveldomain = "toplevel_postfix"
Const OU = "Organisationseinheit"
Const ProfilPfad = "\\PDC\sharename$\"
'****************************************************
'ZugriffsMethode
'1 = Lesen
'2 = Schreiben
'8 = Anhaengen
'****************************************************
Const Zugriff=1 ' Nur zum lesen
call BenutzerEinlesen()
'*****************************************************************
'Unterfunktion zum einlesen der Benutzer
'*****************************************************************
Sub BenutzerEinlesen()
	Dim Nachname,Vorname,Name,Benutzer,PrincipalName,Passwort
	Set fso = CreateObject("Scripting.FileSystemObject")'Objekt zum lesen einer Datei
	Counter=0
	'Testet ob Datei vorhanden
	If fso.FileExists(DateiName) Then
		Set f = fso.OpenTextFile (DateiName,Zugriff,false)'Oeffnet die Datei
		'Schleife die alle Benutzer in ein Array liesst
		Do while not f.AtEndOfLine
			Zeile = f.readLine
			Feld = split(Zeile,",")
			Nachname = Feld(0)'Vorname
			Vorname = Feld(1)'Nachname
			Name = Feld(2)'Voller Name
			PrincipalName=Feld(3)'VollQualifizierterName
 			Benutzer = Feld(4)'Anmeldename
			Counter=Counter+1
			'Ruft Funkktion zum Schreiben der Benutzer in das AD Objekt auf
			Call BenutzerAnlegen(Benutzer,Vorname,Nachname,PrincipalName,Name)
		Loop
		f.Close'SChliesst die Datei
	Else
		WScript.Echo ("Datei ist nicht vorhanden")
	End If
End Sub

'*****************************************************************
'Unterfunktion zum erstelllen der Benutzer
'*****************************************************************
Sub BenutzerAnlegen(Benutzer,Vorname,Nachname,PrincipalName,Name)
	'On Error Resume Next
	'****************************************************
	'Variablen Deklaration
	'****************************************************
	Dim ouo, b, LDAPPfad
	LDAPPfad="LDAP://OU=" & OU & ",DC=" & Domain & ",DC=" & TopLeveldomain
	'****************************************************
	'Setzt den LDAP Pfad
	'****************************************************
	Set ouo = GetObject(LDAPPFAD)
	Set b = ouo.Create("user", "CN=" & Name)
	'****************************************************
	'Zum Aufruf der Bat Datei
	'****************************************************
	Dim WshShell, ret
	Set WshShell = WScript.CreateObject("WScript.Shell")

	'****************************************************
	'Schreibt die Benutzer Daten
	'****************************************************
	b.Put "sAMAccountName", Benutzer
	b.Put "displayName", Name
	b.Put "givenName", Vorname
	b.Put "sn", Nachname
	b.Put "userAccountControl", 66082 And Not 65536
	b.Put "userPrincipalName", PrincipalName
	b.Put "profilePath", ProfilPfad & Benutzer
	b.Put "pwdLastSet",0
	b.SetInfo
	b.SetPassword Passwort
	b.AccountDisabled = False
	b.SetInfo
	WScript.Sleep(1000)
	'****************************************************
	ret = WshShell.Run ("ChangePWonLogon.cmd " & Benutzer)
End Sub

WScript.Echo(Counter & " Benutzer wurden angelegt !")
WScript.Quit(0)