Wednesday, July 7, 2010

System Replacement Script

We have many users with special drive mappings that aren't being mapped in Group Policy - we're still in the Dark Ages in this respect.

Anyway, here's a little script that we run on a system prior to replacing it in our current system refresh:

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDrives = objWMIService.ExecQuery _
("Select * From Win32_LogicalDisk Where DriveType = 4")
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("z:\newsys\mappings.csv", True)
For Each objDrive in colDrives
drive = objDrive.DeviceID
path = objDrive.ProviderName
OutPutFile.Write drive & "," & path & vbcrlf
Next

This script creates a .csv file in the user's home directory, mapped to z:, for later use.

In order to use this script, copy the code and paste it into notepad, saving the file with a .vbs extension.

In order to add it to a batch file, simply add the command cscript filename.vbs.

No comments:

Post a Comment