170 likes | 435 Views
Microsoft Windows Server. Terms. VBScript JavaScript Script Objects Attributes CSVDE LDIFDE. Scripting. What is VBScript? VBScript is a scripting language A scripting language is a lightweight programming language
E N D
Terms VBScript JavaScript Script Objects Attributes CSVDE LDIFDE
Scripting • What is VBScript? • VBScript is a scripting language • A scripting language is a lightweight programming language • VBScript is a “light” version of Microsoft's programming language Visual Basic • How Does it Work? • Web->When a VBScript is inserted into a HTML document, the Internet browser will read the HTML and interpret the VBScript. The VBScript can be executed immediately, or at a later event. • Networking->A VBScript can be compared to a simple batch file. It is in essence a program that will be run by Windows Scripting Host. The benefit/advantage over the batch file is that it is extremely more powerful and flexible.
Windows Scripting Host • There are two ways to launch the scripts. • Wscript (default): GUI Windows scripting host
Windows Scripting Host Cscript: command line scripting host
Examples • Open Notepad • Type the following commands • Option Explicit • Wscript.Echo "Hello, World!“ • Save as hello.vbs
Examples • Mapping a network drive ‘Map drive to share Set WshNetwork =WScript.CreateObject("WScript.Network") WshNetwork.MapNetworkDrive "Z:", \\dp2\shared
Examples 'Function to set a user's password ' 'For more scripts, visit www.wshscripting.com Function SetPassword(domain, username, password) 'Call this Function to set a user's password On Error Resume Next Dim user Set user = GetObject("WinNT://" & domain & "/" & username & "",user) user.SetPassword(password) SetPassword = Err.Number On Error Goto 0End Function 'example Dim username, password, domain domain = InputBox("On what domain", "Domain", "") username = InputBox("Enter a username", "User Name", "") password = InputBox("Enter a new password", "Password", "") If SetPassword(domain, username, password) = 0 Then MsgBox "Successful" Else MsgBox "Error Occurred" End If
Examples Creating an OU Set objDomain = GetObject("LDAP://dc=fabrikam,dc=com") Set objOU = objDomain.Create("organizationalUnit", "ou=Management") objOU.SetInfo
Examples Move a Group Within a Domain Moves a group account from the HR OU to the Users container. Set objOU = GetObject("LDAP://cn=Users,dc=NA,dc=fabrikam,dc=com") objOU.MoveHere "LDAP://cn=atl-users,ou=HR,dc=NA,dc=fabrikam,dc=com", _vbNullString
Examples • Create User Account • Creates a user account in Active Directory. This script only creates the account, it does not enable it. Set objOU = GetObject("LDAP://OU=management,dc=fabrikam,dc=com") Set objUser = objOU.Create("User", "cn=MyerKen") objUser.Put "sAMAccountName", "myerken“ objUser.SetInfo
Example • Create 1000 users in AD Set objRootDSE = GetObject("LDAP://rootDSE") Set objContainer = GetObject("LDAP://cn=Users," & _ objRootDSE.Get("defaultNamingContext")) For i = 1 To 1000 • Set objLeaf = objContainer.Create("User", "cn=UserNo" & i) • objLeaf.Put "sAMAccountName", "UserNo" & I • objLeaf.SetInfo Next WScript.Echo "1000 Users created."
Assigning Login Scripts • Policy based within Group Policy • Computer Specific • Startup/Shutdown Scripts • User Specific • Logon/Logoff Scripts • Run asynchronously (“hidden, behind the scenes”) • W2k3 Machines create share called NETLOGON • \winnt\sysvol\”domain name”\scripts for backwards compatibility
Scripting Resources • http://www.microsoft.com/technet/scriptcenter/default.mspx • http://www.winnetmag.com/WindowsScripting/ • http://www.w3schools.com/vbscript/default.asp
CSVDE & LDIFDE • CSVDE: CSV Directory Exchange • Can import/export objects from Active Directory • Bulk import of only NEW objects. • Cannot modify existing objects • LDIFDE: Lightweight Data Interchange Format Data Exchange • Can import/export objects from Active Directory • Bulk import of objects. • Modification of EXISTING Active Directory accounts. • Resources • http://support.microsoft.com/default.aspx/kb/327620 • http://www.computerperformance.co.uk/Logon/CSVDE_LDIFDE.htm
CSVDE & LDIFDE • Examples • For example, you can use the following command to export all objects with the users.swynk.com as part of their Distinguished Name (including both users and groups) into userlist.csv file: • csvde.exe -f userlist.csv -d "cn=users,DC=swynk,DC=com“ • The following will export all objects of the user object class (user and computer accounts, but not groups): • csvde.exe -f userlist.csv -r "(objectClass=user)"
CSVDE & LDIFDE • The import is less straightforward. Some of attributes are owned by the system, so when running the import using the same file format, errors will result. Running export with -m switch, excludes them (by using so called SAM logic). Once the list is known, it can be populated with data for new user accounts. • For example, the following allows you to create MarcinPolicht account in swynk.com domain: • csvde.exe -i -f indata.csv • indata.csv contains the following fieldsDN,cn,displayName,distinguishedName,objectCategory,objectClass,name,sAMAccountName,givenName,sn,userPrincipalName"CN=MarcinPolicht,CN=Users,DC=swynk,DC=com",MarcinPolicht,MarcinPolicht,"CN=MarcinPolicht,CN=Users,DC=swynk,DC=com","CN=Person,CN=Schema,CN=Configuration,DC=swynk,DC=com",user,MarcinPolicht,MarcinPolicht,Marcin,Policht,MarcinPolicht@swynk.com