13 July 2010

Create a bootable WinPE USB drive with tools

Make USB drive bootable:


  • Diskpart
    • list disk
    • select disk #
    • Clean
    • create partition primary
    • select partition 1
    • Active
    • format quick fs=fat32 or ntfs
    • Assign
    • Exit
Copy WinPE files to USB drive

  • Install WAIK for Windows 7
  • Launch "Deployment Tools Command Promp"
    • Copype x86 c:\winpe
    • Copy c:\winpe\winpe.wim c:\winpe\ISO\sources\boot.win
    • Xcopy c:\winpe\iso\*.* /e :\

Tools

Copy tools to the USB drive
- This is much easier than mounting the wim file on the USB stick with imageX


Using ImageX

But - if we need/want to "install" the stuff in the wim file, then...
(ImageX is part of WAIK)

  • Launch "Deployment Tools Command Promp"
    • Md c:\img
    • Imagex /mountrw :\sources\boot.wim 1 c:\img
      • Do your stuff..
    • Imagex /unmount /commit c:\img

02 July 2010

Import users into Active Directory from csv file

At a customer I should create a bunch of users in the domain.
I could get the users in a csv-file, containing their initials and full name.
Since there were more than 200 account, I created a script to perform this operation.



' create users in AD from csv
'
' CSV file with layout sam, displayname (, password)
'----------------------------------------------------
Option Explicit
Dim sCSVFileLocation
Dim sCSVFile
Dim oConnection
Dim oRecordSet
Dim oNewUser
Dim oRootLDAP
Dim oContainer
Dim sLogon
Dim sFirstName
Dim sDisplayName
Dim sPassword
Dim nPwdLastSet
Dim nUserAccountControl ' Used to enable the account
Dim sDomain

' AD domain, used to append to login name (initials@ADdomain)
sDomain="sc.local"

' Input file, location and filename
sCSVFileLocation = "C:\tools\"
sCSVFile = sCSVFileLocation&"NewUser.csv"

' Commands used to open the CSV file and select all of the records
set oConnection = createobject("adodb.connection")
set oRecordSet = createobject("adodb.recordset")
oConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & _
   sCSVFileLocation &  ";Extended Properties=""text;HDR=yes;FMT=Delimited"""
oRecordSet.open "SELECT * FROM " & sCSVFile ,oConnection

' Create a connection to the Active Directory Users container.
Set oRootLDAP = GetObject("LDAP://rootDSE")
Set oContainer = GetObject("LDAP://ou=Users,ou=Production," & _
   oRootLDAP.Get("defaultNamingContext"))

on error resume next   ' continue if account exist

do until oRecordSet.EOF
' --------- Start creating user account
' Read variable information from the CSV file
' and build everything needed to create the account
sLogon = oRecordSet.Fields.Item(0).value
sDisplayName = trim(oRecordSet.Fields.Item(1).value)
'sPassword = oRecordSet.Fields.Item(2).value 'if specified in csv file
sPassword = "Welcome1" 'same password for all
sFirstName = split(sDisplayName," ",3,1)
  'wscript.echo sLogon & " " & sDisplayName
  'wscript.echo sFirstName(0)
  'wscript.echo sFirstName(1)
' Build the User account
Set oNewUser = oContainer.Create("User","cn="&sDisplayName)
oNewUser.put "sAMAccountName",lcase(sLogon)
oNewUser.put "givenName",sFirstName(0)
oNewUser.put "sn",sFirstName(1)
oNewUser.put "UserPrincipalName",lcase(SLogon)&"@"&sDomain
oNewUser.put "CN",sDisplayName
oNewUser.put "DisplayName",sDisplayName
oNewUser.put "Initials",sLogon     'max 6 chars
oNewUser.put "name",lcase(sLogon)

' Write to AD
oNewUser.SetInfo
' password
oNewUser.SetPassword sPassword
oNewUser.Put "pwdLastSet", 0
' Enable the user account
oNewUser.Put "userAccountControl", 512
oNewUser.SetInfo
' Used only for debugging
if err.number = -2147019886 then
   wscript.echo sLogon & " already exists"
end if
oRecordSet.MoveNext
loop