Migrating from XP to Windows 7 – Inventory What’s There

In the mist of upgrading from Windows XP to Windows 7 on all of our computers, I thought I would share some of the scripts I’m using to make life a little easier.  We currently use local user profiles, printers added manually by hand through a Windows print server and sometimes statically mapped network drives for users that need to perform cross duty work in other departments.

Yes, I give you permission to laugh and yes I know there’s ways of doing these things in an automated and centralized fashion.  Going into the companies we buy, however, I’m seeing even sillier things in their environments.  One was a guy that was using Clonezilla, an external hard drive, a USB stick (at least it wasn’t a CD-ROM) and doing a custom image for each and every model of computer hardware he had.  He had an impressive talent for scripting however and I found many clever VBScript snippets all over the network he was firing via the login script to do things automated and in the background.

The below script is quick, dirty and thrown together from many different sources.  It will give you:

All the drives and UNC paths mapped under the logged in user’s profile

All of the printers networked and local under the logged in user’s profile

The default printer of the logged in user

Names of all Outlook profiles of the logged in user (this will error out if this does not exist)

List of unsorted software as given from WMI

Simply call it as the user from the login script and SCCM and dump the file to some where world writable.  It will dump the contents in plain text to a file in the format of username.computer.txt.

– Soli Deo Gloria

On Error Resume Next

Const HKEY_CURRENT_USER = &H80000001
Const r_ProfilesRoot = "SoftwareMicrosoftWindows NTCurrentVersionWindows Messaging SubsystemProfiles"

strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
 & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2") 
Set colInstalledPrinters = objWMIService.ExecQuery _ 
 ("Select * from Win32_Printer where Default = True") 
For Each objPrinter in colInstalledPrinters 
Dim objFileSystem, objOutputFile
Dim strOutputFile


Set objFileSystem = CreateObject("Scripting.fileSystemObject")

Set Shell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
Set oPrinters = WshNetwork.EnumPrinterConnections
oUser = WshNetwork.UserName

computername = Shell.ExpandEnvironmentStrings("%computername%")

strOutputFile="\\someserver\logs" & oUser & "." & computername & ".txt"
Set objOutputFile = objFileSystem.CreateTextFile(strOutputFile, TRUE)

objOutputFile.WriteLine("Network drive mappings:")
For i = 0 to oDrives.Count - 1 Step 2
objOutputFile.WriteLine("Drive " & oDrives.Item(i) & " = " & oDrives.Item(i+1))
objOutputFile.WriteLine("Network printer mappings:")
For i = 0 to oPrinters.Count - 1 Step 2
objOutputFile.WriteLine("Port " & oPrinters.Item(i) & " = " & oPrinters.Item(i+1))

objOutputFile.WriteLine("Default Printer: ") & PrinterDefault

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _ 
 strComputer & "rootdefault:StdRegProv")

oReg.EnumKey HKEY_CURRENT_USER,r_ProfilesRoot,subKeys

objOutputFile.WriteLine(" ") 
objOutputFile.WriteLine("Outlook Profiles: ") 

For Each profileName In subKeys
 objOutputFile.WriteLine( profileName ) 

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")
Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product")

objOutputFile.WriteLine(" ") 
objOutputFile.WriteLine("Installed Software: ") 

For Each objSoftware in colSoftware
 objOutputFile.WriteLine objSoftware.Caption & ", " & objSoftware.installDate & ", " & objSoftware.installDate2


Set objFileSystem = Nothing