Tuesday, December 23, 2008

vb script to audit installed software

Here's the script I used to audit software installations across our Windows network:

Option Explicit
On Error Resume Next
 
Const strInFile = "c:\scripts\audit\hosts.txt"
Const strOutFile = "C:\scripts\audit\results.csv"
 
Dim arrHosts, objHost, strHost
Dim objFSO, objTextFile
Dim i, strNextLine
Dim fileSystem, objOutFile
 
Set arrHosts = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strInFile, 1)
i = 0
 
Do Until objTextFile.AtEndOfStream 
    strNextLine = objTextFile.Readline
    arrHosts.Add i, strNextLine
    i = i + 1
Loop
 
objTextFile.Close
Set objFSO = Nothing
 
Set fileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set objOutFile = FileSystem.CreateTextFile(strOutFile, True)
 
For Each objHost in arrHosts
 
    strHost = arrHosts.Item(objHost)
 
    WScript.Echo(strHost)
    objOutFile.Write strHost
 
    '----------------        using Win32_Product        ----------------
    Dim objWMIService
    Dim arrItems1, arrItems2
    Dim objItem1, objItem2
    
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strHost & "\root\cimv2")
    Set arrItems1 = objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
'   Set arrItems2 = objWMIService.ExecQuery("SELECT * FROM Win32_Product")
'   Set arrItems2 = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE (Caption LIKE '%Office%')")
'   Set arrItems2 = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE SoftwareElementID = '{90280409-6000-11D3-8CFE-0050048383C9}'")
 
    objOutFile.Write(",")
    
    For Each objItem1 in arrItems1
        Dim strCaption
        strCaption = objItem1.Caption
        strCaption = Replace(strCaption, ",", "")
        strCaption = Replace(strCaption, ";", ":")
        
        objOutFile.Write strCaption
        WScript.Echo("   " & strCaption)
'       objOutFile.Write "," & objItem1.Version
'       objOutFile.Write "," & objItem1.InstallDate
'       objOutFile.Write "," & objItem1.RegisteredUser
'       objOutFile.Write "," & objItem1.SerialNumber
 
        strCaption = vbEmpty
    Next
 
    '----------------        using the registry        ----------------
    Dim strKey, strSubKey
    Dim objRegistry
    Dim arrSubKeys()
    Dim strDisplayName, strDisplayVersion, strInstallLocation
    Const HKEY_LOCAL_MACHINE = &H80000002
 
    strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strHost & "\root\default:StdRegProv")
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKey, arrSubKeys
 
    objOutFile.Write(",")
 
    For Each strSubKey In arrSubKeys
        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayName", strDisplayName
'        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "DisplayVersion", strDisplayVersion
'        objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKey & "\" & strSubKey, "InstallLocation", strInstallLocation
 
        If strDisplayName <> 0 Then
            strDisplayName = Replace(strDisplayName, ",", "")
            strDisplayName = Replace(strDisplayName, ";", ":")
            
            objOutFile.Write(strDisplayName & ";")
            WScript.Echo("      " & strDisplayName)        
        End If
 
        strDisplayName = vbEmpty
        strDisplayVersion = vbEmpty
        strInstallLocation = vbEmpty
    Next
 
    Set objWMIService = Nothing
    Set arrItems1 = Nothing
    Set arrItems2 = Nothing
    Set objRegistry = Nothing
    objOutFile.Write vbcrlf
Next
 
objOutFile.Close
Set fileSystem = Nothing

Friday, December 19, 2008

transferring FSMO roles in Windows 2003

In my migration process from Windows 2000 Server domain controllers to Windows Server 2003, I transferred FSMO roles to the new servers.

You must be logged on to the target server with domain administrator privileges. Then, at a command prompt, do this:

001
ntdsutil
002
roles
003
connections
004
connect to server <servername>
005
q
006
008
transfer domain naming master
007
010
transfer infrastructure master
009
012
transfer pdc
011
014
transfer rid master
013
016
transfer schema master

015

see also:

Wednesday, November 26, 2008

migrate WINS from Windows 2000 Server to 2003

I need to migrate WINS from a Windows 2000 Server to a Windows 2003 Server host.

I. put WINS on the 2003 Server

1. install WINS on the 2003 Server

Start > Control Panel > Add or Remove Programs >

Components > Networking Services > Details

Subcomponents of Networking Services > Windows Internet Name Service (WINS) > OK >

001

Next > Continue >

Finish > Close.

2. point TCP/IP services at this WINS server

Start > Control Panel > Network Connections > Properties >

General > Internet Protocol (TCP/IP) > Properties > Advanced >

WINS > Add >

[put the ip address of the 2003 Server] > Add >

check 'Enable NetBIOS over TCP/IP'

002

OK > Close.

3. check that this WINS Server appears within the WINS service

Start > Programs > Administrative Tools > WINS >

...and the 2003 Server name should appear here:

003

II. copy the WINS database from the Windows 2000 Server host to the Windows Server 2003 host

1. verify that this WINS server is not replicating

on the Windows 2000 Server-based host, open the WINS service and right click the server icon to stop any replication partners:

001

2. stop the WINS service on both servers

Start > Run > type 'cmd' > OK

type 'net stop wins' > ENTER

002

3. copy the WINS files

copy all files in %systemroot%\System32\Wins from the 2000 Server to the same location on the 2003 Server:

003

004

4. restart the WINS service on both servers

Start > Run > type 'cmd' > OK

type 'net start wins' > ENTER

006

III. set up a WINS replication partnership

I have to gradually phase out my old Windows 2000 Server from its WINS responsibilities. Because there are dozens of servers here whose IP settings were manually configured and point to the old server for WINS, I need to set up a replication partnership between the old and new WINS servers. This partnership will need to function until all clients, those receiving DHCP and those that are manually configured, are communicating with the new server.

set up a WINS replication partner in Windows 2000 Server (same for Windows 2003):

Start > Programs > Administrative Tools > WINS >

right-click the 'Replication Partners' node > New Replication Partner... >

enter the IP address of the other WINS server

092

There are 2 areas worth configuring: the push settings and the pull settings. By again right-clicking the 'Replication Partners' node and selecting 'Properties' you can get in to the settings for these 2 items. Push Replication is based on revision number while Pull Replication is based on time. Both are typically used.

093

094

you should see the replication partner appear, here:

095

...and on the Windows 2003 Server, the old WINS server will automatically appear:

092

Settings for Windows Server 2003 are the same as for Windows 2000 Server.

IV. change DHCP scope settings

it's time to point DHCP clients at the new WINS server:

008

009 

see also:

Friday, November 14, 2008

migrate DHCP from Windows 2000 Server to 2003

These are brief instructions. Microsoft has the full-value version, here: How to move a DHCP database from a computer that is running Windows NT Server 4.0, Windows 2000, or Windows Server 2003 to a computer that is running Windows Server 2003. If you're like me, you don't wear a helmet, and you will appreciate my brevity. And actually, I changed a couple things.

One notable difference between me and whoever documents technical procedures for Microsoft is that I work on Earth, for a company, and my implementation must not cause an explosion. We have a bunch of VLANs, managed by Cisco routers, that are configured with the ip helper-address command to ensure DHCP broadcasts are forwarded from clients to the DHCP server. I deviate from Microsoft's generic recommendation for DHCP service migration in this way: I will move one VLAN at a time. This allows me to test things as I go, knowing both servers are handling at least some DHCP scopes, affecting as few clients as possible in the event of catastrophe, and giving myself a clear method for reversing my changes. Also, by adjusting the ip helper-address value on my core routers one VLAN at a time I am able to prevent the new and old DHCP servers from handing out addresses for the same subnet.

I. export the DHCP database from the Windows 2000 Server host

1. stop the DHCP service

command line: net stop dhcpserver

002

2. compact the DHCP data base

command line: cd c:\winnt\system32\dhcp

command line: jetpack dhcp.mdb temp.mdb

004

3. export the database

download, install, and run Microsoft's DHCP Database Export Import Tool (dhcpexim.exe)

006

007

4. restart the DHCP service

command line: net start dhcpserver

009

II. import the DHCP database to the new Windows Server 2003 host

1. install the Windows DHCP component

Start > Control Panel > Add or Remove Programs > Add/Remove Windows Comonents > Netwoking Services >

001

Details >

002

Dynamic Host Configuration Protocol (DHCP) > OK > Next > Finish

2. import the database file

command line: netsh dhcp server import c:\dhcpdb.txt all

003

3. authorize this DHCP server

before authorizing:

004

right-click the server object, then click Authorize

005

III. point the ip helper-address at the new DHCP server

existing configuration, pointing at the old DHCP server:

001

in Cisco IOS, use this command: ip helper-address 172.16.12.12

002

IV. confirm

I set my Vista laptop to retrieve an ip address from a DHCP server and plugged it in to a port on the VLAN we just set up...

001

002

have my laptop send a DHCP request on to this subnet...

command line: ipconfig /renew

004

and confirm on the new DHCP server that this address was handed out by the new server...

008

V. change DHCP lease duration

If you let Windows DHCP do it's own thing, leases will automatically expire after 8 days. But if you want to speed things up, change the DHCP lease duration to something like 2 hours. At least then you'll know sooner if something's broken.

change DHCP lease duration in Windows 2000 Server:

Start > Programs > Administrative Tools > DHCP >

096

expand the server node you're interested in > right click the scope whose lease you want to change > Properties > on the 'General' tab, in the 'Lease duration for DHCP clients' box, check 'Limited to:' and specify a time span

097

VI. turn on DHCP logging

Just in case any clients got left behind, check the DHCP log files for unexpected requests. Do this on the Windows 2000 Server for a couple weeks.

to turn on DHCP logging in Windows 2000 Server:

Start > Programs > Administrative Tools > DHCP >

090

on the 'General' tab, select 'Enable DHCP audit logging'

Windows 2000 will write DHCP log files, one for each day of the week, to this directory: %systemroot%\system32\dhcp

091

093

see also: