19 November 2010

DISM works - injecting drivers into wim files

I have a WDS server with some images.
And sometimes one have to update images with new drivers,
and here is how I do it, using DISM:

Wim info:

Dism /Get-WimInfo /WimFile:f:\remoteinstall\boot\x86\images\boot.wim
Dism /Get-WimInfo /WimFile:f:\remoteinstall\boot\x86\images\boot.wim /index:2

Mount Win:
Dism  /Mount-Wim /Wimfile:f:\remoteinstall\boot\x86\images\boot.wim /index:2 /MountDir:f:\mount

Add Drivers:
just one:
Dism /image:f:\mount /add-driver /driver:f:\ibm_drivers\mr
a whole library:
Dism /image:f:\mount /add-driver /driver:f:\ibm_drivers /recurse


Unmount wim and commit:
Dism /Unmount-Wim /MountDir:f:\mount /commit

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

18 June 2010

"Configuring Microsoft office" - every time you start an office applikation

On my Win7 box, I was running office 2003. The I decided to upgrade to the new Offiece 2010 (rtm)..
Oh, what troublesome....
The installation went fine - no problem..
BUT.. every time I started an office application, the splash came up: "Configuring Microsoft Office Standard 2010"..
So... remove the office installation.. install again - same shit.
Windows Installer Cleanup tool - same shit.
Reg-hacks - no...
The complete manual remove (as described in a KB article from MS) - and fresh install.... same shit..

UNTIL....
I came upon this little hint:

secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose

-and that did it... now my office 2010 is running nicely..

11 May 2010

Script: Change DNS settings on servers in AD

I had a customer where new DNS servers was setup (that was - new DCs with AD integrated DNS). To change DNS server settings on the Nic, facing the produktion network, on all servers in the domain, I wrote this script.

Using RootDse, no domain name is hardcoded.
The script checks the AD for servers,
then it check all NICs on the server to see if there is DNS settings matching the ip's given in strings strODNS1 and strODNS2.
If a match is found, the DNS settings are changed to the ip's given in strNDNS1 and strNDNS2.
Same is done regarding WINS settings.
A logfile - DNS.TXT - are created, listing servernames and changes made.
-------------------------------------------------------------------------------

'Change DNS and WINS on NICs

'
On Error Resume Next

'Old settings
strODNS1="192.168.1.19"
strODNS2="192.168.1.10"
strOWins1="192.168.1.19"
strOWins2="192.168.1.10"

'New settings
strNDNS1="192.168.1.19"
strNDNS2="192.168.1.100"
strNWins1="192.168.1.19"
strNWins2="192.168.1.100"

Const ADS_SCOPE_SUBTREE = 2
Const strLogFile = "DNS.TXT"
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f

'Delete log file if it exists
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strLogFile) then
   fso.DeleteFile strLogFile
end if

WriteLog "Started: " & date
WriteLog " "

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
Set RootDse = GetObject( "LDAP://RootDse" )
strADSPath = "LDAP://" & RootDse.get( "DefaultNamingContext" )

objCommand.CommandText = "Select Name,operatingSystem from '" & strADSPath & "' Where objectClass='computer' and OperatingSystem='*server*'"

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
   objServer = objRecordSet.Fields("Name").Value
   wscript.echo "Checkin server: " & objServer
   WriteLog "Checking server: " & objServer
   'objOS = objRecordset.Fields("OperatingSystem").value
   'wscript.echo objOS

   strComputer = objServer
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
   Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

   For Each objAdapter in colAdapters
      If Not IsNull(objAdapter.IPAddress) Then
         For i = 0 To UBound(objAdapter.IPAddress)
            'WScript.Echo " IP address: " & objAdapter.IPAddress(i)
            'WriteLog " IP: " & objAdapter.IPAddress(i)
         Next
      End If

      If Not IsNull(objAdapter.DNSServerSearchOrder) Then
         For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
            'WScript.Echo " DNS " & objAdapter.DNSServerSearchOrder(i)
            'WriteLog " DNS " & objAdapter.DNSServerSearchOrder(i)
            if (objAdapter.DNSServerSearchOrder(i) = strODNS1) or (objAdapter.DNSServerSearchOrder(i) = strODNS2) then
               writeLog " - dns settings changed ..."
               objAdapter.SetDNSServerSearchOrder Array (strNDNS1,strNDNS2)
            end if
         Next
      End If

      'WriteLog " WINS1: " & objAdapter.WINSPrimaryServer
      'WriteLog " WINS2: " & objAdapter.WINSSecondaryServer
      if (objAdapter.WINSPrimaryServer = strOWins1) or (objAdapter.WINSPrimaryServer = strOWins2) then
         objAdapter.SetWINSServer strNWins1,strNWins2
         WriteLog " - WINS settings are changed..."
      end if
   Next

   WriteLog " "
   objRecordSet.MoveNext
Loop

Function WriteLog(aStr)
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile(strLogFile, ForAppending, True)
   f.WriteLine aStr
   f.Close
   Set f = Nothing
   Set fso = Nothing
End Function

05 May 2010

Remote scripting on Windows Server 2008

If you leave the windows firewall turned on on your Windows Server 2008 boxes, you are not allowed to run script against a remote server.
The windows firewall will block these attemps.

Running in a domain, the fastest way to allow remote script execution, is to create a group policy...
Create a new GPO and drill to:
Computer Configuration -> Policies -> Administrative Templates -> Network -> Network Connections -> Windows Firewall -> Domain Profile
Set "Windows Firewall: Allow inbound remote administration exception" to "Enabled"
- and configure with a specific ip address (if only one machine is allowed for remote scripting)or a subnet (the subnet from where the remote script will be fired).

29 April 2010

WINS - access denied to wins server in wins mmc

And just as we thought wins was dead.....
it comes right back and keeps hunting you.

The case:
I had to install the WINS service on a DC.
No problem - easy and fast done..
BUT... when starting the WINS mmc... ACCESS DENIED to the wins server !!!!

well... the solution
edit permissions on reg-key HKEY_LOCAL_MACHINE\SYSTEM\CurentControlSet\Control\SecurePipeServers\winreg

"LOCAL SERVICE" needs to be added with Read permissions.

Then it worked.....