rss

Retired Scripts: "Get Mapped Drives and Printers"

Here's a little script I built to run before client migration.  Instead of touching hundreds of machines and checking for custom drive and printer mapping, this script builds a general list on a network drive and saves details on the local machine.  It also builds in a remap batch for post migration desktop support.

 

dpmapback.wsf

<job>
<script language="VBScript">
'******************************************************************************
'* Get mapped drives and printers 
'* 
'* Modified: 2:13 PM 12/13/2005 -j. bilinski
'******************************************************************************
On Error Resume Next
strComputer = "."
 
'***User strings
Const strNetDBloc = "\\127.0.0.1\testshare\"
Const strNetDDB = "drivemaps.csv"
Const strNetPDB = "printermaps.csv"
Const strLocalDBfile = "oldmaps.txt"
 
 
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set colSystemEnvVars = objWshShell.Environment("System")
Set colUserEnvVars = objWshShell.Environment("User")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshNetwork = CreateObject("WScript.Network")
Set objADSysInfo = CreateObject("ADSystemInfo")
Set strNetOutputLine = ""
Set strLocalOutputLine = ""
Set strCurrentUser = ""
Set intNoNetUpdate = 0
Set arrMapDrives = objWshNetwork.EnumNetworkDrives
Set arrMapPrinters = objWshNetwork.EnumPrinterConnections
 
 
'***
'strCurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strCurrentUser = objWshNetwork.UserName
strProfileDir = objWshShell.SpecialFolders.Item("MyDocuments")
strNetDDBfile = strNetDBloc & strCurrentUser & strNetDDB
strNetPDBfile = strNetDBloc & strCurrentUser & strNetPDB
Wscript.Echo strCurrentUser
Wscript.Echo strProfileDir
Wscript.Echo strNetDDBfile
 
 
 
If objFSO.FileExists(strProfileDir & "\" & strLocalDBfile) Then 
intNoNetUpdate = 1
Set objLocalFile = objFSO.OpenTextFile(strProfileDir & "\" & strLocalDBfile, 8, True)
Else
Set objLocalFile = objFSO.CreateTextFile(strProfileDir & "\" & strLocalDBfile, True)
End If
 
If intNetUpdate = 0 Then
 Set objMountFile1 = objFSO.OpenTextFile(strNetDDBfile, 8, True)
 For i = 0 to arrMapDrives.Count - 1 Step 2
  strNetOutputLine = strCurrentUser & "," & arrMapDrives.Item(i) & "," & arrMapDrives.Item(i+1)
  objMountFile1.WriteLine(strNetOutputLine) 
  strLocalOutputLine = "NET USE " & arrMapDrives.Item(i) & " " & arrMapDrives.Item(i+1)
  objLocalFile.WriteLine(strLocalOutputLine)
  Wscript.Echo strNetOutputLine
  Wscript.Echo strLocalOutputLine
 Next
 objMountFile1.Close
 Set objMountFile2 = objFSO.OpenTextFile(strNetPDBfile, 8, True)
 For i = 0 to arrMapPrinters.Count - 1 Step 2
  strOutputLine = strCurrentUser & "," & arrMapPrinters.Item(i) & "," & arrMapPrinters.Item(i+1)
  objMountFile2.WriteLine(strNetOutputLine) 
  strLocalOutputLine = "NET USE " & arrMapPrinters.Item(i+1)
  objLocalFile.WriteLine(strLocalOutputLine)
 Next
 objMountFile2.Close
Else
 For i = 0 to arrMapDrives.Count - 1 Step 2 
  strLocalOutputLine = "NET USE " & arrMapDrives.Item(i) & " " & arrMapDrives.Item(i+1)
  objLocalFile.WriteLine(strLocalOutputLine)
 Next
 For i = 0 to arrMapPrinters.Count - 1 Step 2
  strLocalOutputLine = "NET USE " & arrMapPrinters.Item(i+1)
  objLocalFile.WriteLine(strLocalOutputLine)
  Wscript.Echo strLocalOutputLine
 Next
End If
 
objLocalFile.Close
 
Wscript.Quit
</script>
</job>
 

More Script Dumps...

Bookmark


TrackBack URL: http://bilinski.org/trackback.ashx?id=25


Leave a Comment

 

 (optional/private)

(optional/public)